C-program to calculate profit or loss

0
43
#include <stdio.h>
int main()
{
    /*declare the variables*/
    int cp;
    int sp;
    int amount;
    
/*enter the cost price*/
    printf("Enter the cost price: ");
    scanf("%d", &cp);
    
/*enter the selling price*/
    printf("Enter the selling price: ");
    scanf("%d", &sp);
    
/*if condition*/
    if (sp > cp) 
{
        /*formula to find profit*/
        amount = sp - cp;
        printf("profit = %d", amount);
 }
/*else if condition*/
    else if (cp > sp) 
{
/*formula to find loss*/
        amount = cp - sp;
        printf("loss = %d", amount);
}
/*else condition*/
    else 
{
        printf("No profit no loss\n");
}
    return 0;
}
Output:
Enter the cost price: 2000 
Enter the selling price: 1500
loss = 500

LEAVE A REPLY

Please enter your comment!
Please enter your name here