यदि विक्रय मूल्य लागत मूल्य से अधिक है तो लाभ ज्ञात करने का सूत्र निम्नानुसार है:
profit=sellingPrice-CostPrice;
यदि लागत मूल्य विक्रय मूल्य से अधिक है तो हानि ज्ञात करने का सूत्र निम्नानुसार है:
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