- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Given a certain cost price(cp) and a selling price(sp) of an unknown product or a service, our task is to find the profit earned or loss suffered using a C program where if the profit is earned should print “Profit” and it’s amount or if the loss is suffered “Loss” and its respective amount or if there is not profit no loss then print “No profit nor Loss”.

To find the profit or the loss we generally see whether the selling price(sp) or the price/amount at which a certain thing is sold or the cost price(cp) at which a certain thing is bought. If the cost price(cp) is higher than the selling price(sp) then it is believed that there is loss, and their difference will be the total loss suffered. When the selling price(sp) is higher than the cost price(cp) then it is believed that profit is earned, and their difference is the total profit.

**Input** − cp = 149, sp = 229

**Output** − Profit 80

**Explanation** −selling price(sp) > cost price(cp), so there is profit of sp-cp=80

**Input** − cp = 149, sp = 129

**Output** −Loss 20

**Explanation** −cost price(cp) > selling price(sp), so there is loss of cp-sp=20

Take the cost price and selling price as input

Check if cost price > selling price, then it is a loss find difference and return the result.

Check if selling price > cost price, then it is a profit find difference and return the result.

And if selling price == cost price, then there is not profit nor a loss.

Start In function int Profit(int cp, int sp) Step 1→ Return (sp - cp) In function int Loss(int cp, int sp) Step 1→ Return (cp - sp) In function int main() Step 1→ Declare and initialize cp = 5000, sp = 6700 Step 2→ If sp == cp then, Print "No profit nor Loss" Step 3→ Else if sp > cp Print Profit Step 4→ Else Print Loss Stop

#include <stdio.h> //Function will return profit int Profit(int cp, int sp){ return (sp - cp); } // Function will return Loss. int Loss(int cp, int sp){ return (cp - sp); } int main(){ int cp = 5000, sp = 6700; if (sp == cp) printf("No profit nor Loss\n"); else if (sp > cp) printf("%d Profit\n", Profit(cp, sp)); else printf("%d Loss\n", Loss(cp, sp)); return 0; }

If run the above code it will generate the following output −

1700 Profit

- Related Questions & Answers
- What is difference between profit and loss account and profit and loss appropriate account?
- Compare balance sheet and profit and loss account
- C++ program to calculate Profit Or Loss
- What is difference between profit and loss account and trading account?
- Write about profit and loss(P/L) on financial statement.
- Path Loss - Solved Numerical Problems from Wireless Communications
- Find cost price from given selling price and profit or loss percentage in C++
- Hysteresis Loss and Eddy Current Loss
- Write a C program to find out profit or loss in buying an article
- Differentiate between accounting profit and taxable profit
- Write the difference between accounting profit and economic profit.
- Losses in DC Machine – Iron Loss, Copper Loss and Mechanical Losses
- Differentiate between turnover and profit.
- Path Loss Definition, Overview and Formula
- Explain the Decidable and undecidable problems

Advertisements