Skip to content

Instantly share code, notes, and snippets.

@saiedabbas93
Last active January 24, 2023 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saiedabbas93/533936c9f4788a48a719b1031ca03754 to your computer and use it in GitHub Desktop.
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.
#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");
}
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>
@kusal6199
Copy link

can you please update it to profit percent and loss percent too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment