Computer Science, asked by ayush6434, 1 year ago

Write a program to accept Cost price and Selling price and check whether shopkeeper faced gain or loss

Answers

Answered by ashajain93
2
C program to find profit and loss, given cost price and selling price
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* Given cost price and selling price, Write a
* C program to calculate Profit or loss
*/

#include <stdio.h>

int main() {
int costPrice, sellingPrice;

/*
* Take costPrice and SellingPrice as input from user
*/
printf("Enter Cost Price and Selling Price\n");
scanf("%d %d", &costPrice, &sellingPrice);

if(costPrice > sellingPrice) {
/* Loss */
printf("Loss = %d\n", costPrice - sellingPrice);
} else if(sellingPrice > costPrice) {
/* Profit or Gain*/
printf("Profit = %d\n", sellingPrice - costPrice);
} else {
/* No Profit or Loss*/
printf("No Profit and No Loss\n");
}

return 0;
}

Output
Enter Cost Price and Selling Price
5 10
Profit = 5
Enter Cost Price and Selling Price
12 8
Loss = 4
Enter Cost Price and Selling Price
10 10
No Profit and No Loss
Similar questions