C Program to Enter Cost Price and Selling Price and Find Profit or Loss

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
C program to calculate simple interest
C program to calculate compound interest
C program to find total, average and percentage marks of subjects
C program to count number of digits in an integer
C program to convert binary number to decimal number system
C program to convert kilometer to miles
C program to find factorial of a number using recursion
C program for palindrome check using recursion
C program to insert an element in an array
List of all C programs