C Program to Find Profit, Loss or No Profit No Loss लाभ, हानि या न लाभ न हानि ज्ञात करने का C प्रोग्राम
When a product is purchased at a certain price and sold at another price, we can determine whether a profit or loss has occurred by comparing the cost price and selling price.
जब कोई वस्तु एक निश्चित कीमत पर खरीदी जाती है और दूसरी कीमत पर बेची जाती है, तो क्रय मूल्य और विक्रय मूल्य की तुलना करके लाभ या हानि ज्ञात की जा सकती है।
Cost Price (CP): The price at which a product is purchased.
क्रय मूल्य (CP): वह मूल्य जिस पर कोई वस्तु खरीदी जाती है।
Selling Price (SP): The price at which a product is sold.
विक्रय मूल्य (SP): वह मूल्य जिस पर कोई वस्तु बेची जाती है।
Formulas (सूत्र)
Profit (लाभ) = Selling Price − Cost Price, when SP > CP.
Loss (हानि) = Cost Price − Selling Price, when CP > SP.
No Profit, No Loss (न लाभ, न हानि), when SP = CP.
C Program
#include <stdio.h>
int main(void)
{
float sp, cp, pl;
printf("Enter Cost Price and Selling Price: ");
scanf("%f %f", &cp, &sp);
pl = sp - cp;
if (pl > 0)
{
printf("Profit = %.2f Rs\n", pl);
}
else if (pl == 0)
{
printf("No Profit, No Loss\n");
}
else
{
printf("Loss = %.2f Rs\n", -pl);
}
return 0;
}Sample Output 1: Profit (लाभ)
Enter Cost Price and Selling Price: 500 700
Profit = 200.00 RsSample Output 2: Loss (हानि)
Enter Cost Price and Selling Price: 800 600
Loss = 200.00 RsSample Output 3: No Profit, No Loss (न लाभ, न हानि)
Enter Cost Price and Selling Price: 500 500
No Profit, No LossExplanation in English
The variables
cpandspstore the cost price and selling price, respectively.The statement
pl = sp - cp;calculates the difference between the selling price and cost price.If
pl > 0, the selling price is greater than the cost price, so the program displays the profit.If
pl == 0, both prices are equal, so there is no profit and no loss.If
pl < 0, the cost price is greater than the selling price, so the program displays the loss. The expression-plconverts the negative difference into a positive loss amount.
हिंदी में व्याख्या
cpऔरspवेरिएबल क्रमशः क्रय मूल्य और विक्रय मूल्य को स्टोर करते हैं।pl = sp - cp;स्टेटमेंट विक्रय मूल्य और क्रय मूल्य का अंतर ज्ञात करता है।यदि
pl > 0है, तो विक्रय मूल्य क्रय मूल्य से अधिक है। इसलिए लाभ प्रदर्शित होता है।यदि
pl == 0है, तो दोनों मूल्य समान हैं। इसलिए न लाभ होता है, न हानि।यदि
pl < 0है, तो क्रय मूल्य विक्रय मूल्य से अधिक है। इसलिए हानि प्रदर्शित होती है।-plएक्सप्रेशन हानि की राशि को धनात्मक रूप में प्रदर्शित करता है।
This program demonstrates the use of the if-else-if statement and relational operators in C.
यह प्रोग्राम C भाषा में if-else-if स्टेटमेंट और रिलेशनल ऑपरेटर्स के उपयोग को समझाता है।
Comments
Post a Comment