Write a C program to find out profit or loss in buying an article


The formula for finding profit is as follows if the selling price is greater than cost price −

profit=sellingPrice-CosePrice;

The formula for finding loss is as follows if cost price is greater than selling price −

loss=CostPrice-SellingPrice

Now, apply this logic in the program and try to find whether the person gets a profit or loss after buying any article −

Example

Following is the C program to find the profit or loss −

 Live Demo

#include<stdio.h>
int main(){
   float CostPrice, SellingPrice, Amount;
   printf("
Enter the product Cost : ");    scanf("%f", &CostPrice);    printf("
Enter the Selling Price) : ");    scanf("%f", &SellingPrice);    if (SellingPrice > CostPrice){       Amount = SellingPrice - CostPrice;       printf("
Profit Amount = %.4f", Amount);    }    else if(CostPrice> SellingPrice){       Amount = CostPrice - SellingPrice;       printf("
Loss Amount = %.4f", Amount);    }    else       printf("
No Profit No Loss!");    return 0; }

Output

When the above program is executed, it produces the following result −

Enter the Product Cost: 450
Enter the Selling Price): 475.8
Profit Amount = 25.8000

Updated on: 08-Mar-2021

200 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements