Thursday, 14 March 2013

Determine a seller’s profit or loss and how much



Statement:
If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.



ü           Algorithm:

                                    Step-1: Read a (cost price)
                                    Step-2: Read b (selling price)
                                    Step-3: if(a>b)
1)      Print “LOSS”
2)      c=a-b
3)      The amount loss is  c
                                    Step-4: else
1)      print “PROFIT”
2)      c=b-b
3)      The amount of profit c
                                    Step-5: End
                       


v                        Program Listing:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c;
printf("Enter the cost price=");
scanf("%f",&a);
printf("\nEnter the selling price=");
scanf("%f",&b);
if (a>b)
{
printf("\nSeller incurred LOSS");
c=a-b;
printf("\nThe LOSS is=%f",c);
}
else
{
printf("\nSeller makes PROFIT");
c=b-a;
printf("\nThe PROFIT is=%f",c);
}
getch();
}



·        Output:
Enter the cost price= 102
Enter the selling price= 112
Seller makes PROFIT
The PROFIT is=10


Enter the cost price= 156
Enter the selling price= 114
Seller incurred LOSS
The LOSS is=42
                                   
           
           
§  Discussion:
                                                                                I.            It works within the number range -32767 to 32767
                                                                              II.            If we use long integer then it works in more than range.
                                                                            III.            It works in negative number.

No comments:

Post a Comment