- 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 with the cost price(CP) and the selling price(SP) and the task is to calculate the profit gained or loss incurred.

Cost price or CP is the price at which the product is purchased by the seller and the selling price or SP is the price at which the product is sold by the seller.

There is a formula to calculate profit gained or loss incurred

Profit = Selling price – Cost price

If Selling price is greater than cost price than there will be a profit

Loss = Cost price – Selling price

If cost price is greater than selling price than there will be a loss

Input-: CP = 600 SP = 100 Output-: loss incurred = 500 Input-: CP = 100 SP = 500 Output-: profit gained = 400

Approach used in the given program is as follows −

- Take the input as cost price and selling price
- Apply the formula given to calculate profit or loss
- Display the result

Start Step 1-> declare function to calculate Profit. int profit(int CP, int SP) set int profit = (SP - CP) return profit step 2-> Declare function to calculate Loss int loss(int CP, int SP) set int loss = (CP - SP) return loss step 3-> In main() set int CP = 600, SP = 100 IF (SP == CP) Print "No profit nor Loss" End Else IF (SP > CP) call profit(CP, SP) End Else Call loss(CP , SP) End Stop

#include <iostream> using namespace std; // Function to calculate Profit. int profit(int CP, int SP) { int profit = (SP - CP); return profit; } // Function to calculate Loss. int loss(int CP, int SP) { int loss = (CP - SP); return loss; } int main() { int CP = 600, SP = 100; if (SP == CP) cout << "No profit nor Loss"; else if (SP > CP) cout<<"profit gained = "<< profit(CP, SP); else cout<<"loss incurred = "<<loss(CP , SP); return 0; }

IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT

loss incurred = 500

- Related Questions & Answers
- Profit and loss Problems using C
- Write a C program to find out profit or loss in buying an article
- C++ Program to calculate the profit sharing ratio
- What is difference between profit and loss account and profit and loss appropriate account?
- Find cost price from given selling price and profit or loss percentage in C++
- Compare balance sheet and profit and loss account
- Write about profit and loss(P/L) on financial statement.
- What is difference between profit and loss account and trading account?
- C program to calculate age
- C++ Program to Calculate Standard Deviation
- C++ Program to calculate Double Integration
- Hysteresis Loss and Eddy Current Loss
- C++ Program to Calculate Power Using Recursion
- Write C program to calculate balance instalment
- C program to calculate the standard deviation

Advertisements