판매가가 원가보다 클 경우 이익을 구하는 공식은 다음과 같습니다 -
profit=sellingPrice-CosePrice;
원가가 판매가보다 큰 경우 손실을 구하는 공식은 다음과 같습니다. -
loss=CostPrice-SellingPrice
이제 이 논리를 프로그램에 적용하고 그 사람이 어떤 기사를 구매한 후 이익을 얻거나 손실을 입는지 알아보십시오 -
예시
다음은 손익을 구하는 C 프로그램입니다 -
#include<stdio.h>
int main(){
float CostPrice, SellingPrice, Amount;
printf("\n Enter the product Cost : ");
scanf("%f", &CostPrice);
printf("\n Enter the Selling Price) : ");
scanf("%f", &SellingPrice);
if (SellingPrice > CostPrice){
Amount = SellingPrice - CostPrice;
printf("\n Profit Amount = %.4f", Amount);
}
else if(CostPrice> SellingPrice){
Amount = CostPrice - SellingPrice;
printf("\n Loss Amount = %.4f", Amount);
}
else
printf("\n No Profit No Loss!");
return 0;
} 출력
위의 프로그램이 실행되면 다음과 같은 결과가 생성됩니다 -
Enter the Product Cost: 450 Enter the Selling Price): 475.8 Profit Amount = 25.8000