This is the basic program to perform profit and loss operation in C language. It is helpful to calculate the profit, loss, profit percentage, and loss percentage. And you can also see the basic profit and loss formulas and the definitions.

## C Program to perform profit and loss operation

**Source Code:**

```
// c program to perform profit and loss operation
#include <stdio.h>
// funtion body to display all profit and loss basic definations
void dispDef(){
printf("INTRO: Profit and Loss formula is used in mathematics to determine the price of a commodity in the market and understand how profitable a business is. Every product has a cost price and selling price. Based on the values of these prices, we can calculate the profit gained or the loss incurred for a particular product.");
printf("\n\nCOST PRICE(CP): The amount paid for a product or commodity to purchase it is called a cost price. Also, denoted as CP.\n\tThis cost price is further classified into two different categories:\n\t\t1)Fixed Cost: The fixed cost is constant, it does not vary under any circumstances \n\t\t2)Variable Cost: It could vary depending as per the number of units");
printf("\n\nSELLING PRICE(SP): The amount for which the product is sold is called Selling Price. It is usually denoted as SP. Also, sometimes called a sale price.");
printf("\n\nPROFIT(P): The amount gained by selling a product with more than its cost price.");
printf("\n\nLOSS(L): The amount the seller incurs after selling the product less than its cost price, is mentioned as a loss.");
}
//fuction body to display formula of profit and loss
void dispFor(){
printf("\n**Profit & Loss Formulas**");
printf("\n1: Profit or Gain = Selling price – Cost Price\n2: Loss = Cost Price – Selling Price\n3: Profit percentage = (Profit /Cost Price) x 100\n4: Loss percentage = (Loss / Cost price) x 100");
}
// function body to calculate profit and loss
void calPL(){
//variable declation
float p, l, sp, cp;
//enter selling price
printf("Enter selleing price:");
scanf("%f",&sp);
//enter cost price
printf("Enter cost price:");
scanf("%f",&cp);
//case of profit
if(sp>cp){
p = sp - cp;
printf("Profit is:%f",p);
}
//case of loss
else if(cp>sp){
l = cp - sp;
printf("Loss is:%f",l);
}
//case of no profit and no loss
else{
printf("No Profit & No Loss.");
}
}
//funtion body to calculate profit percent
void calProfitPercent(){
//declation of variable
float pPer, p, cp;
//enter cost price
printf("Enter cost price:");
scanf("%f",&cp);
//enter profit
printf("Enter profit:");
scanf("%f",&p);
//calculating profit percentage
pPer = (p/cp)*100;
//printing profit percentage
printf("Profit Percentage is:%f",pPer);
}
//loss pecentage calculation funtion body
void calLossPercent(){
//variables diclaration
float l, lPer, cp;
//enter cost price
printf("Enter cost price:");
scanf("%f",&cp);
//enter loss
printf("Enter your loss:");
scanf("%f",&l);
//calculating loss percentage
lPer = (l/cp)*100;
//printing loss percentage
printf("Loss Percentage is:%f",lPer);
}
// operation funtion body
void operation(){
//declration of variables
int ch;
//statement to show the operations
printf("\n1:Display all Definations\n2:Display all formula \n3:Calculate profit or gain & loss \n4:calculate profit percentage\n5:calulate loss percentage");
//statements to enter users choice
printf("\nEnter your choice:");
scanf("%d",&ch);
//switch case to perform operation choosen by user
switch (ch){
//case for calling display defination function
case 1:
dispDef();
break;
//case for calling display formula function
case 2:
dispFor();
break;
//case for calling profit and loss calculation funtion
case 3:
calPL();
break;
//case for calling profit percent calculation funtion
case 4:
calProfitPercent();
break;
//case for calling loss percent calculation funtion
case 5:
calLossPercent();
break;
// default switch funtion
default:
printf("\nEnter correct choice from (1-5):");
}
}
int main() {
//variable declaration
int n;
x:
// calling profit and loss operation funtion
operation();
//ask for performing operation again
printf("\nDo you want to perform again for yes enter 1 or for no enter 0:");
scanf("%d",&n);
//if user want to perform again
if(n==1){
goto x;
}
//if user not want to perform gain
else{
printf("\nThanks for choosing us........");
}
return 0;
}
```

**Input & Output:**

```
1:Display all Definitions
2:Display all formula
3:Calculate profit or gain & loss
4:calculate profit percentage
5:calulate loss percentage
Enter your choice:2
**Profit & Loss Formulas**
1: Profit or Gain = Selling price – Cost Price
2: Loss = Cost Price – Selling Price
3: Profit percentage = (Profit /Cost Price) x 100
4: Loss percentage = (Loss / Cost price) x 100
Do you want to perform again for yes enter 1 or for no enter 0:1
1:Display all Definitions
2:Display all formula
3:Calculate profit or gain & loss
4:calculate profit percentage
5:calulate loss percentage
Enter your choice:3
Enter selling price:1000
Enter cost price:500
Profit is:500.000000
Do you want to perform again for yes enter 1 or for no enter 0:0
Thanks for choosing us........
```