C Program to find Profit and Loss
Write a C Program to calculate Profit and Loss?
Hi, We are back with another simple program. In this program, we will learn how to write a program to find profit and loss with the use of if-else statement to calculate profit and loss in C Language.
We all have learned about profit and loss in primary mathematics classes. So, If cost price is greater than selling price then there is a loss otherwise it is a profit.
The basic formula to calculate profit and loss
Profit = S.P – C.P (Where S.P is Selling Price and C.P is Cost Price)
Loss = C.P – S.P
Lets see the programming part:
#include<stdio.h>
int loss(int selling_price)
{
int cost,difference;
if(selling_price>cost)
{
difference=selling_price-cost;
printf(“%d is profit\n”,difference);
}
else
{
printf(“%d is loss\n”,difference);
}
}
int main()
{
int selling,price,difference;
printf(“enter the price”);
scanf(“%d”,&price);
printf(“enter the selling “);
scanf(“%d”,&selling);
loss(selling);
return 0;
}
Let us know if you have any question or any idea, just leave a comment.