C Program to calculate Profit or Loss – In this article, we will brief in on the way to calculate the profit or the loss on a given commodity or service.
Only the standard method will be used to calculate the same.
Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.
As it is imminent, there are two prices associated with any particular commodity or service.
Those are as follows:
- Cost Price
- Selling Price
The Cost Price is the price at which the seller has bought something by themselves or the manufacturer’s overall expenditure behind making the same.
The Selling Price is the price at which someone sells the product or service to someone else.
As it is evident from the photo above, Profit is attained when the Selling Price is greater than the Cost Price. In this case, the seller will be able to accumulate some extra money from the buyer.
Similarly, Loss is incurred when the Selling Price is less than the Cost Price. In this situation, the seller has to shell extra amount to sell the product or service to the buyer.
Profit = Selling Price – Cost Price
Loss = Cost Price – Selling Price
Both the values are positive.
Using Standard Method
1)Read the cost price and selling price.
2)Compare the cost price with selling price using if condition.
If selling price>= cost price then profit= selling price-cost price.
otherwise, loss= cost price – selling price.
printf("Enter cost price: ");
printf("Enter selling price: ");
if(sp >= cp)
p= sp - cp;
printf("Profit = %d",p);
printf("Loss = %d",l);
Enter cost price: 155
Enter selling price: 156
Profit = 1
Enter cost price: 1000
Enter selling price: 900
Loss = 100