C program to calculate profit and loss on a transaction

C program to calculate profit and loss on a transaction

Q:-Write a C program to calculate profit and loss on a transaction

This C program to calculate profit or loos helps the user to enter the actual amount and Sales Amount. Using those two values, this C Program will check whether the product is in profit or Loss using Else If.

#include<stdio.h>
#include<conio.h>
void main() 
{
   int cp, sp;  
 clrscr(); 
 
    printf("Enter the cost price of the product\n");  
    scanf("%d", &cp);  
  
    printf("Enter the selling price of the product\n");  
    scanf("%d", &sp);  
  
    if(sp > cp)  
    {  
        printf("Your profit is %d\n", (sp-cp));  
    }  
    else if(cp > sp)  
    {  
        printf("Loss Incurred is %d\n", (cp-sp));  
    }  
    else  
    {  
        printf("Neither profit, nor loss\n");  
    }  
getch();
 }

Output

We ask the user to enter cost price as well as selling price. If selling price is more than cost price, then the seller is in profit. If the cost price is more than selling price, then the seller incurred loss.

TOP