C program to check calculate profit or loss using conditional operator












C program to check calculate profit or loss using conditional operator.




C program to check calculate profit or loss using conditional operator



#include <stdio.h> int main() { int cost_price,selling_price; printf("Enter cost price: "); scanf("%d", &cost_price); printf("Enter selling price: "); scanf("%d", &selling_price); (selling_price > cost_price)? printf("Profit = %d", selling_price - cost_price): (cost_price > selling_price)? printf("Loss = %d", cost_price - selling_price): printf("No Profit No Loss."); return 0; }


Output:
Enter cost price: 5000 Enter selling price: 5500 Profit = 500 Enter cost price: 5000 Enter selling price: 4500 Loss = 500 Enter cost price: 5000 Enter selling price: 5000 No Profit No Loss.