Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Write a C program to find out profit or loss in buying an article
The formula for finding profit is as follows if the selling price is greater than cost price −
profit=sellingPrice-CosePrice;
The formula for finding loss is as follows if cost price is greater than selling price −
loss=CostPrice-SellingPrice
Now, apply this logic in the program and try to find whether the person gets a profit or loss after buying any article −
Example
Following is the C program to find the profit or loss −
#include<stdio.h>
int main(){
float CostPrice, SellingPrice, Amount;
printf("
Enter the product Cost : ");
scanf("%f", &CostPrice);
printf("
Enter the Selling Price) : ");
scanf("%f", &SellingPrice);
if (SellingPrice > CostPrice){
Amount = SellingPrice - CostPrice;
printf("
Profit Amount = %.4f", Amount);
}
else if(CostPrice> SellingPrice){
Amount = CostPrice - SellingPrice;
printf("
Loss Amount = %.4f", Amount);
}
else
printf("
No Profit No Loss!");
return 0;
}
Output
When the above program is executed, it produces the following result −
Enter the Product Cost: 450 Enter the Selling Price): 475.8 Profit Amount = 25.8000
Advertisements