
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Profit and loss Problems using C
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
Approach used below is as follows to solve the problem
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.
Algorithm
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
Example
#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
"); else if (sp > cp) printf("%d Profit
", Profit(cp, sp)); else printf("%d Loss
", Loss(cp, sp)); return 0; }
Output
If run the above code it will generate the following output −
1700 Profit
- Related Articles
- Calculating profit or loss using Python
- What is difference between profit and loss account and profit and loss appropriate account?
- C++ program to calculate Profit Or Loss
- Compare balance sheet and profit and loss account
- How to Create a Profit and Loss Calculator using HTML, CSS, and JavaScript?
- What is difference between profit and loss account and trading account?
- Write about profit and loss(P/L) on financial statement.
- Find cost price from given selling price and profit or loss percentage in C++
- Path Loss - Solved Numerical Problems from Wireless Communications
- Profit or Loss percent is always calculated on_____________.
- Write a C program to find out profit or loss in buying an article
- How to find Profit or loss using Python when CP of N items is equal to SP of M
- Common Problems and Solutions When Using Microsoft Office
- Differentiate between accounting profit and taxable profit
- Hysteresis Loss and Eddy Current Loss
