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 Rs

Sample Output 2: Loss (हानि)

Enter Cost Price and Selling Price: 800 600
Loss = 200.00 Rs

Sample Output 3: No Profit, No Loss (न लाभ, न हानि)

Enter Cost Price and Selling Price: 500 500
No Profit, No Loss

Explanation in English

  1. The variables cp and sp store the cost price and selling price, respectively.

  2. The statement pl = sp - cp; calculates the difference between the selling price and cost price.

  3. If pl > 0, the selling price is greater than the cost price, so the program displays the profit.

  4. If pl == 0, both prices are equal, so there is no profit and no loss.

  5. If pl < 0, the cost price is greater than the selling price, so the program displays the loss. The expression -pl converts the negative difference into a positive loss amount.

हिंदी में व्याख्या

  1. cp और sp वेरिएबल क्रमशः क्रय मूल्य और विक्रय मूल्य को स्टोर करते हैं।

  2. pl = sp - cp; स्टेटमेंट विक्रय मूल्य और क्रय मूल्य का अंतर ज्ञात करता है।

  3. यदि pl > 0 है, तो विक्रय मूल्य क्रय मूल्य से अधिक है। इसलिए लाभ प्रदर्शित होता है।

  4. यदि pl == 0 है, तो दोनों मूल्य समान हैं। इसलिए न लाभ होता है, न हानि।

  5. यदि pl < 0 है, तो क्रय मूल्य विक्रय मूल्य से अधिक है। इसलिए हानि प्रदर्शित होती है। -pl एक्सप्रेशन हानि की राशि को धनात्मक रूप में प्रदर्शित करता है।

This program demonstrates the use of the if-else-if statement and relational operators in C.

यह प्रोग्राम C भाषा में if-else-if स्टेटमेंट और रिलेशनल ऑपरेटर्स के उपयोग को समझाता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Top High-Paying Tech Skills to Learn in 2025

Complete C Programming Syllabus | Advanced C Roadmap for Students