# Calculate Profit or Loss in C Programming

In our last program we saw How to Calculate Simple Interest in C Programming. In this program, we will make use of if-else block to calculate profit or loss in C. It will also print the profit or loss amount accordingly.This is a problem from Chapter 1: Getting Started of the book, “Let us C” by “Yashwant Kanetkar”.

### Question

Write a program to check if a seller has made profit or loss.

### Solution to Calculate Profit or Loss in C

Declare four variables for cost price, selling price, profit and loss. Accept cost price & selling price from user using printf() and scanf(). Use if block to check if SP is greater than CP. If selling price is more, then store the difference between selling price and cost price in profit variable and print the profit, else store the difference between cost price and selling price in loss variable & print the loss.

### Source Code:

``` /*Program to find profit or loss */
#include<stdio.h>
#include<conio.h>
void main()
{
int cp, sp, profit, loss;
clrscr();
printf("Enter the value of Cost Price & Selling Price: ");
scanf("%d %d",&cp,&sp);

if(sp>cp)
{
profit=sp-cp;
printf("The seller has made profit of %d",profit);
}
else
{
loss=cp-sp;
printf("The seller has suffered loss of %d",loss);
}
getch();
}```

## Output

Enter the value of Cost Price & Selling Price: 350 450
The seller has made profit of 100

Let us know if you are stuck somewhere and need help. You are also free to request some other problem using our comments section or contact form and we will try our best to provide you a solution to your problem. Alternatively, you can also contact us on our social media pages.