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.
So,
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <stdio.h> int main() { int cp,sp,p,l; printf("Enter cost price: "); scanf("%d", &cp); printf("Enter selling price: "); scanf("%d", &sp); if(sp >= cp) { p= sp - cp; printf("Profit = %d",p); } else { l=cp-sp; printf("Loss = %d",l); } return 0; } |
1 2 3 4 5 6 7 8 |
Enter cost price: 155 Enter selling price: 156 Profit = 1 Enter cost price: 1000 Enter selling price: 900 Loss = 100 |