C Programming

Solved Example

Practice Questions

Exercise Question

Calculate cost price

Objective

Enter the selling price and profit earned for 20 items and find the cost price of each item.

Program / Solution:

#include<stdio.h>
int main() {
	int profit,sp;
	float cp;
	
	printf("Enter the selling price and profit earned for 20 times: ");
	scanf("%d%d",&sp,&profit);
	
	cp = sp - profit;
	
	cp = (float)cp / 20;
	
	printf("Cost price of each item: %.2f",cp);
	
	return 0;
}

Sample Output:

Enter the selling price and profit earned for 20 times: 275 72
Cost price of each item: 10.15