Slip 11 - A) Write a C program to accept the cost price and selling price from the user. Find out if the seller has made a profit or loss and display how much profit or loss has been made.

Solution:


#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;
}

Post a Comment

0 Comments