Here, we have a basic program example to calculate profit and loss using different languages. This program is created in c language, c++, Java, and Python.
Program to calculate profit and loss in C language
#include <stdio.h>
void main()
{
int cost_price,selling_price, profit_amnt;
printf("Input Cost Price: ");
scanf("%d", &cost_price);
printf("Input Selling Price: ");
scanf("%d", &selling_price);
if(selling_price>cost_price)
{
profit_amnt = selling_price-cost_price;
printf("\nYou can booked your profit amount : %d\n", profit_amnt);
}
else if(cost_price>selling_price)
{
profit_amnt = cost_price-selling_price;
printf("\nYou got a loss of amount : %d\n", profit_amnt);
}
else
{
printf("\nYou are running in no profit no loss condition.\n");
}
}
Program to calculate profit and loss in C++ language
#include<iostream>
using namespace std;
int main()
{
int cost_price,selling_price, profit_amnt;
cout<<"Input Cost Price: ";
cin>>cost_price;
cout<<"Input Selling Price: ";
cin>>selling_price;
if(selling_price>cost_price)
{
profit_amnt = selling_price-cost_price;
cout<<"\nYou can booked your profit amount : "<< profit_amnt;
}
else if(cost_price>selling_price)
{
profit_amnt = cost_price-selling_price;
cout<<"\nYou got a loss of amount : "<<profit_amnt;
}
else
{
cout<<"\nYou are running in no profit no loss condition.\n";
}
}
Program to calculate profit and loss in Python language
cost_price = int(input("Input cost price: "))
selling_price = int(input("Input cost price: "))
if(selling_price>cost_price):
profit_amnt = selling_price-cost_price
print("\nYou can booked your profit amount : ", profit_amnt)
elif(cost_price>selling_price):
profit_amnt = cost_price-selling_price
print("\nYou got a loss of amount : ", profit_amnt)
else:
print("\nYou are running in no profit no loss condition.\n")
Program to calculate profit and loss in Java language
import java.util.*;
public class price {
public static void main(String[] args) {
int cost_price, selling_price, profit_amnt;
Scanner s=new Scanner(System.in);
System.out.println("Input Cost Price: ");
cost_price = s.nextInt();
System.out.println("Input Selling Price: ");
selling_price = s.nextInt();
if(selling_price>cost_price)
{
profit_amnt = selling_price-cost_price;
System.out.println("You can booked your profit amount : "+profit_amnt);
}
else if(cost_price>selling_price)
{
profit_amnt = cost_price-selling_price;
System.out.println("You got a loss of amount : "+profit_amnt);
}
else
{
System.out.println("You are running in no profit no loss condition.");
}
}
}