Problem: C program for "If the cost price and selling price of an item is input through keyboard, write a program to determine whether the seller has made a profit or incurred loss. also determine how much profit he made or loss he incurred."
Logic used :
- Input cost price and selling price
- Check if cost price is greater than selling price
- Loss = cost price - selling price
- Else check if selling price is greater than cost price
- Profit = selling price - cost price
- Else no profit , no loss
Formulae used :
Profit = selling price - cost price
Loss = cost price - selling price
C program :
// Program by shyam kanth#include <stdio.h>int main(){int sp,cp;printf("Enter the cost price of item : ");scanf("%d",&cp);printf("Enter the selling price : ");scanf("%d",&sp);if(cp>sp){printf("Seller has incurred loss.\n");printf("Total loss : %d.",cp-sp);}else if(sp>cp){printf("Seller has made profit.\n");printf("Total profit : %d.",sp-cp);}else{printf("No profit and loss made.");}return 0;}
- #include < stdio.h > : Header file for input-output
- int : Integer data type
- sp, cp : Variable used
- printf : Function used for displaying message
- scanf : Function used for taking input
- if-else : Conditional statement
- else if : Else if ladder
Do comments, if any doubt
Know about me : Shyam Kanth
No comments:
Post a Comment