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 | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Tuesday, June 25, 2019

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 | My CS Tutorial


In this tutorial,we will learn how write a program to find the loss or profit of a seller.


C program to calculate profit or loss

We will write a C program that determine how much profit seller made or loss he incurred.

We will write to calculate profit or loss of a seller.



Solution:


  • In this program we will use two header files.
  • In this program we will use four variable cp,sp,loss and pro.
  • We declared these variable in float data type.
  • Then we will enter the value of cost price (cp) and selling price (sp).
  • We will use if else statement with one conditions which is (cp>sp).
  • We will use logics as...                                         loss=cp-sp;   and     loss=cp-sp;
  • And after it we will print the statement or body.
  • When we use these statement the condition execute own statement and print the value.
  • If the condition is false the else statement will be executed and print the value.


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
float cp,sp,loss,pro;

printf("\n Enter the cost price of an item=");
scanf("%f",&cp);

printf("\n Enter the selling price of an item=");
scanf("%f",&sp);

if(cp>sp)
{
loss=cp-sp;
printf("\n The seller has suffered the loss.The loss is=%f",loss);
}
else
{
pro=sp-cp;
printf("\n The seller has gain the profit.The profit is=%f",pro);
}

getch();
}


Output 1:





Output 2:





We will write a C program that determine how much profit seller made or loss he incurred. We will use four variable cp,sp,loss and pro and declared it in float data type.

          We will use if else statement and logic for calculate profit or loss.


In the first compiler will check the if condition. If the condition is true then the statement of if will be executed otherwise else statement will be executed.


I hope that you understand everything easily.If you have any problem or question so you write a comment and follow me on this blog and my Facebook page and on Instagram.Share the post.




No comments:

Post a Comment