C Exercises: Calculate profit and loss
18. Profit and Loss Calculation
Write a C program to calculate profit and loss on a transaction.
Visual Presentation:
For more Practice: Solve these Related Problems:
- Write a C program to calculate profit or loss percentage from cost and selling prices and display a detailed report.
- Write a C program to compute profit or loss and output whether the transaction breaks even.
- Write a C program to calculate profit/loss and determine the break-even point for a series of transactions.
- Write a C program to accept cost and selling prices, compute profit/loss, and apply a discount factor if applicable.
Sample Solution:
C Code:
#include <stdio.h> // Include the standard input/output header file.
void main()
{
int cprice, sprice, plamt; // Declare variables to store cost price, selling price, and profit/loss amount.
printf("Input Cost Price: "); // Prompt user for input of cost price.
scanf("%d", &cprice); // Read and store the cost price.
printf("Input Selling Price: "); // Prompt user for input of selling price.
scanf("%d", &sprice); // Read and store the selling price.
if(sprice > cprice) // Check if selling price is greater than cost price.
{
plamt = sprice - cprice; // Calculate profit amount.
printf("\nYou can book your profit amount : %d\n", plamt); // Print profit message.
}
else if(cprice > sprice) // Check if cost price is greater than selling price.
{
plamt = cprice - sprice; // Calculate loss amount.
printf("\nYou incurred a loss of amount : %d\n", plamt); // Print loss message.
}
else // If neither profit nor loss.
{
printf("\nYou are in a no profit, no loss condition.\n"); // Print message for no profit, no loss.
}
}
Output:
Input Cost Price: 500 Input Selling Price: 700 You can booked your profit amount : 200
Flowchart:
C Programming Code Editor:
Previous: Write a C program to check whether an alphabet is a vowel or consonant.
Next: Write a program in C to calculate and print the Electricity bill of a given customer.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.