Calculate Profit or Loss in C Programming

By Apr 12, 2017 No Comments

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”.


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.

Download the solution:

Download Program

Source Code:

 /*Program to find profit or loss */
 void main()
 int cp, sp, profit, loss;
 printf("Enter the value of Cost Price & Selling Price: ");
 scanf("%d %d",&cp,&sp);

 printf("The seller has made profit of %d",profit);
 printf("The seller has suffered loss of %d",loss);



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

Download the solution:

Download Program

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.

Read Also:

Introduction to C Programming

Calculate gross salary in C

Subtracting two numbers in C

Multiplying two numbers in C

Harsh Shah

Harsh Shah

Geek, Tech Crazy, Wannabe Entrepreneur, Blogger, Freelancer, Noob

Leave a Reply