C Program to Find Profit or Loss

C program to find profit or loss; In this tutorial, i am going to show you how to write a program to calculate profit or loss in c program.

C Program to Find Profit or Loss

/**
 * C program to calculate profit or loss
 */
#include <stdio.h>
int main()
{
    int cp,sp, amt; 
    
    /* Input cost price and selling price of a product */
    printf("Enter cost price: ");
    scanf("%d", &cp);
    printf("Enter selling price: ");
    scanf("%d", &sp);
    
    if(sp > cp)
    {
        /* Calculate Profit */
        amt = sp - cp;
        printf("Profit = %d", amt);
    }
    else if(cp > sp)
    {
        /* Calculate Loss */
        amt = cp - sp;
        printf("Loss = %d", amt);
    }
    else
    {
        /* Neither profit nor loss */
        printf("No Profit No Loss.");
    }
    return 0;
}

The output of the above c program; as follows:

Enter cost price: 1000
Enter selling price: 2500
Profit = 1500

More C Programming Tutorials

Leave a Comment