Write a C program to enter cost price and selling price of a product and check for any profit or loss also calculate total profit or loss using if else. How to calculate profit or loss on any product using if else in C programming. Program to calculate profit and loss of any product in C.

Input cost price: 1000

Input selling price: 1500

Output profit: 500

Profit = S.P - C.P (Where S.P is Selling Price and C.P is Cost Price)

Loss = C.P - S.P

Happy coding ;)

**Example:**Input cost price: 1000

Input selling price: 1500

Output profit: 500

### Required knowledge

Basic C programming, If else, Basic Mathematics, Profit loss formula.### Logic to find profit or loss

If the cost price is greater than selling price then there is a loss otherwise profit. Formula to calculate profit or lossProfit = S.P - C.P (Where S.P is Selling Price and C.P is Cost Price)

Loss = C.P - S.P

### Program to calculate profit or loss

/** * C program to calculate profit or loss */ #include <stdio.h> int main() { int cp,sp, amt; /* Reads cost price and selling price of a product */ printf("Enter cost price: "); scanf("%d", &cp); printf("Enter selling price: "); scanf("%d", &sp); if(sp > cp) //Profit { amt = sp - cp; printf("Profit = %d", amt); } else if(cp > sp) //Loss { amt = cp - sp; printf("Loss = %d", amt); } else //No Profit No Loss { printf("No Profit No Loss."); } return 0; }

Output

Enter cost price: 1000

Enter selling price: 1500

Profit = 500

Enter selling price: 1500

Profit = 500

Happy coding ;)

### You may also like

- If else programming exercises index.
- C program to enter two number and perform all arithmetic operations.
- C program to enter P, T, R and calculate Simple Interest.
- C program to enter P, T, R and calculate Compound Interest.
- C program to calculate total, average and percentage of marks of five subjects.
- C program to enter any number and check whether it is divisible by 5 and 11 or not.
- C program to enter any number and check whether it is negative, positive or zero.
- C program to enter marks of five subject calculate percentage and grade.
- C program to check whether a triangle is valid or not if all angles are given.
- C program to enter basic salary of an employee and calculate gross salary.

: An electricity board charges according to the following rates:

ReplyDeleteFor the first 100 units - 40 paisa per unit.

For the next 200 units - 50 paisa per unit.

beyond 300 units - 60 paisa per unit.

All users are charged meter charges also, which are Rs. 50/- NEED HELP FOR C CODING PLS REPLY

Hey @Varun, here is a similar program to calculate electricity bill in C. You just need to make few changes only.

Delete