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

CServer Side ProgrammingProgramming

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("\n Enter the product Cost : ");
   scanf("%f", &CostPrice);
   printf("\n Enter the Selling Price) : ");
   scanf("%f", &SellingPrice);
   if (SellingPrice > CostPrice){
      Amount = SellingPrice - CostPrice;
      printf("\n Profit Amount = %.4f", Amount);
   }
   else if(CostPrice> SellingPrice){
      Amount = CostPrice - SellingPrice;
      printf("\n Loss Amount = %.4f", Amount);
   }
   else
      printf("\n 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
raja
Published on 08-Mar-2021 09:55:39
Advertisements