Saturday, January 30, 2010

CHAP 2[C]a Determine profit from cost and sell price

If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

void main()
{
float cp,sp,p;
printf("\nInput the cost price and selling price of an item");
scanf("%f%f",&cp,&sp);
p=sp-cp;
if(p>0)
printf("\nSeller has made a profit of %f",p);
else if(p<0)
printf("\nSeller has made a loss of %f",p=0-p);
else
printf("\nSeller has neither profit nor suffer a loss");
}

No comments:

Post a Comment