C Programming

Solved Example

Practice Questions

Exercise Question

Calculate profit or loss


Input the cost price and selling price of a product. Write a program to check that seller made profit or loss also prints the profit and loss occurred.

Program / Solution:

int main() {
	int cp,sp;
	printf("Enter the cost price and selling price: ");
	scanf("%d %d",&cp,&sp);
	if(sp > cp) {
		printf("Profit = %d",sp - cp);
	} else if(cp > sp) {
		printf("Loss = %d",cp - sp);
	} else {
		printf("No Profit, No Loss");
	return 0;

Sample Output:

Enter the cost price and selling price: 104 200
Profit = 96

More Progarms of Decision Making in C

Check a number is even or odd

Check a number is positive or negative

Check a year is leap year or not

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check a point is inside,outside or on the circle

Check the axis of a point

Identify a character is alphabet, digit and more

Check the insurance eligibility and calculate premium

Calculate the library penalty charges

Calculate grade of a student