|Profit or Loss program in c| | calculate profit or loss in c|

 C program to find profit and loss

code:

#include<stdio.h>
int main()
{
int cp,sp,profit,loss;
printf("enter the cost price:");
scanf("%d",&cp);
printf("enter the selling price:");
scanf("%d",&sp);
if(sp<cp)
{
/*loss*/
loss=cp-sp;
printf("loss %d",loss);
}
else
{
/*profit*/
    profit=sp-cp;
printf("profit %d",profit);
}
return 0;
}

Explanation:


  • Declaring the variable like "cp" for cost price "sp" for selling price and amount in integer datatype.
  • Collecting details from the users like selling price and cost price .
  • Storing the information using scanf statement in cp and sp .
  • Using if condition , we are checking that whether selling price is lesser than cost price 
  • If the condition becomes true which mean that selling price is lesser than cost price then there is a profit , so the condition becomes true .
  • As the condition becomes true it execute the statement inside "profit"
  • If the condition becomes false which mean if selling price is higher than the cost price the condition becomes false so the else part will be executed where the loss part will get executed.

For example:

If the selling price of 1kg Apple is Rs.500 and the cost price of 1kg of Apple is Rs.600?
 
The answer will "Loss"
because, the selling price is higher then cost price.  

To find the loss 

amount=cp-sp
amount=600-500
loss=100

Output:


Loss


Profit 





Comments

Popular posts from this blog

Use of Backslash "\n" in C language

COHESION AND COUPLING material

Coding and Testing in software engineering