Last active
January 24, 2023 11:20
-
-
Save saiedabbas93/533936c9f4788a48a719b1031ca03754 to your computer and use it in GitHub Desktop.
If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
void main() | |
{ | |
int cp,sp,tl,tp; | |
printf("Enter the Cost price\n"); | |
scanf("%d",&cp); | |
printf("Enter the Selling price\n"); | |
scanf("%d",&sp); | |
if(sp>cp) | |
{ | |
tp=sp-cp; | |
printf("The profit is %d",tp); | |
} | |
else if (sp<cp) | |
{ | |
tl=cp-sp; | |
printf("The loss is %d",tl); | |
} | |
else | |
printf("There is neither profit nor loss"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output: | |
Enter the Cost price | |
100 | |
Enter the Selling price | |
200 | |
The profit is 100 | |
PS C:\Program code> cd "c:\Program code\" ; if ($?) { gcc costprice_ifelse.c -o costprice_ifelse } ; if ($?) { .\costprice_ifelse } | |
Enter the Cost price | |
500 | |
Enter the Selling price | |
500 | |
There is neither profit nor loss | |
PS C:\Program code> cd "c:\Program code\" ; if ($?) { gcc costprice_ifelse.c -o costprice_ifelse } ; if ($?) { .\costprice_ifelse } | |
Enter the Cost price | |
500 | |
Enter the Selling price | |
499 | |
The loss is 1 | |
PS C:\Program code> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you please update it to profit percent and loss percent too