Profit is calculated by subtracting cost price from selling price.
That is, Profit = SellingPrice - CostPrice
C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
int p,cp,sp;
printf("Enter Cost Price:");
scanf("%d",&cp);
printf("Enter Selling Price:");
scanf("%d",&sp);
p=sp-cp;
printf("Profit from the item is %d",p);
return 0;
}
Java Program
import java.util.Scanner;
public class Profit {
public static void main(String[] args)
{
Scanner S = new Scanner(System.in);
int p,cp,sp;
System.out.print("Enter cost Price:");
cp = S.nextInt();
System.out.print("Enter Selling Price:");
sp=S.nextInt();
p=sp-cp;
System.out.print("Profit from the item is " + p);
}
}
0 Comments:
Post a Comment