Profit and Loss Program in C

Let’s have a glance at how to find the profit and loss by using the C programming language.

How to calculate profit?

We can use the following formulae to calculate profit & loss.

Profit= Selling Price-Cost Price 
Loss= Cost Price- Selling Price

C Program to find the profit and Loss

#include<stdio.h>
int main()
{
    int cp,sp,tmp;
    printf("Enter the cost of 1 producs\n");
    scanf("%d",&cp);
    printf("Enter the selling price of 1 product\n");
    scanf("%d",&sp);
    tmp=sp-cp;
    if(tmp==0)
     {
      printf("No profit");
     }
     else if(tmp>0)
      {
       printf("Profit=%d", tmp);
      }
     else
      {
       tmp=-1*tmp;
       printf("Loss=%d", tmp);
      }
 }

Output

Enter the cost of 1 producs                                                                                                   
5                                                                                                                             
Enter the selling price of 1 product                                                                                          
2                                                                                                                             
Loss=3

Leave a Comment

Your email address will not be published. Required fields are marked *