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

  • Write a C program to enter cost price and selling price and find profit or loss using if else statement.

Required Knowledge

  • 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

C program to find profit and loss, given cost price and selling price

/* 
 * Given cost price and selling price, Write a 
 * C program to calculate Profit or loss 
 */  
  
#include <stdio.h>  
  
int main() {  
    int costPrice, sellingPrice; 
      
    /* 
     * Take costPrice and SellingPrice as input from user 
     */  
    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