This blog is under construction

Monday, 8 July 2013

C program to calculate profit and loss

Write a C program to calculate profit or loss percentage.


  #include <stdio.h>
  int main() {
        float sp, cp, profit, loss, gpercent, lpercent;

        /* get the cost price and selling price from user */
        printf("Enter the cost price:");
        scanf("%f", &cp);
        printf("Enter the selling price:");
        scanf("%f", &sp);

        /* if sp == cp, no profit */
        if (sp - cp == 0) {
                printf("Profit & gain percent is 0!!\n");
        } else if ((sp - cp) > 0) {
                /* sp > cp - profit and profit percentage calculation */
                profit = sp - cp;
                gpercent = (profit * 100) / cp;
                printf("Profit = %.2f Rupees\n", profit);
                printf("Gain percentage = %.2f percent\n", gpercent);
        } else {
                /* cp > sp - loss and loss percentage calculation */
                loss = cp - sp;
                lpercent = (loss * 100) / cp;
                printf("Loss = %.2f Rupees\n", loss);
                printf("Loss Percentage = %.2f percent\n", lpercent);
        }
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the cost price:100
  Enter the selling price:128
  Profit = 28.00 Rupees
  Gain percentage = 28.00 percent






See Also:

1 comment:

  1. I have something special for you
    today!

    This Profiteering Software App usually
    retails at $497 but for my subscribers
    it’s FREE!

    This is invite only: http://five-minute-profit-sites.net?CCM114

    ReplyDelete