Saturday, November 3, 2018

27. WAP to calculate the profit and loss incurred.

#include<stdio.h>
#include<conio.h>
void main()
{
   float cp,sp,profit,loss,profit_per,loss_per;
   printf("Enter the Cost Price of the item: Rs. ");
   scanf("%f",&cp);
   printf("Enter the Selling Price of the item: Rs. ");
   scanf("%f",&sp);
   if(sp>cp)
   {
      profit=sp-cp;
      profit_per=profit/cp*100;
      printf("\nA Profit of %0.2f% has been made.",profit_per);
   }
   else if(cp>sp)
   {
      loss=cp-sp;
      loss_per=loss/cp*100;
      printf("\nA Loss of %0.2f% has been made.",loss_per);
   }
   else
      printf("\nNo loss no profit.");
   getch();
}


Output:




Please have a look at the below lesson posted on my YouTube channel:

No comments:

Post a Comment