In this C program, we will learn to calculate Profit or Loss from given cost price and selling price.
- If Selling Price > Cost Price
Profit = Selling Price - Cost Price - If Selling Price < Cost Price
Loss = Cost Price - Selling Price - If Selling Price = Cost Price
No Profit .. No Loss
Required Knowledge
C program to find profit and loss, given cost price and selling price
#include <stdio.h> int main() { int costPrice, sellingPrice; printf("Enter Cost Price and Selling Price\n"); scanf("%d %d", &costPrice, &sellingPrice); if(costPrice > sellingPrice) { /* Loss */ printf("Loss = %d\n",costPrice - sellingPrice); } else if(sellingPrice > costPrice) { /* Profit or Gain*/ printf("Profit = %d\n", sellingPrice - costPrice); } else { /* No Profit or Loss*/ printf("No Profit and No Loss\n"); } return 0; }
Output
Enter Cost Price and Selling Price 5 10 Profit = 5
Enter Cost Price and Selling Price 12 8 Loss = 4
Enter Cost Price and Selling Price 10 10 No Profit and No Loss
Related Topics