C Program to find profit or loss
Program
#include<stdio.h>
void main()
{
float cost, sell, profit;
printf("Enter the cost price:\t");
scanf("%f", &cost);
printf("Enter the selling price:\t");
scanf("%f", &sell);
if (sell > cost)
{
profit = sell - cost;
printf("Profit gained:\t%f\n", profit);
}
else if (cost > sell)
{
profit = cost - sell;
printf("Loss incurred:\t%f\n", profit);
}
else
printf("No profit or loss\n");
}
Output 1
Enter the cost price: 560.20
Enter the selling price: 611.15
Profit gained: 50.950012
Output 2
Enter the cost price: 320.88
Enter the selling price: 250.00
Loss incurred: 70.880005
Output 3
Enter the cost price: 830.00
Enter the selling price: 830.00
No profit or loss