Find Greatest of Three Numbers in C — Complete Guide with Program & Explanation

अगर आप Find Greatest of Three Numbers in C Program को सीखना चाहते हैं, तो आप बिल्कुल सही जगह पर आए हैं। यह C programming के सबसे basic और important concepts में से एक है, जो हर beginner को जरूर सीखना चाहिए। इस program के जरिए आप if-else logic, comparison operators, और user input को handle करना सीखते हैं।

इस blog post में हम एक simple लेकिन practical C program देखेंगे जो user से तीन numbers input लेता है और उनमें से सबसे बड़ा number find करके display करता है। Program के साथ-साथ हम हर line का step-by-step explanation भी करेंगे ताकि आपको पूरी logic clearly समझ आए।

चाहे आप अपनी exam की तैयारी कर रहे हों, college assignment complete करनी हो, या simply C programming सीखना चाहते हों — यह guide आपके लिए complete reference की तरह काम करेगी। Program code, output, explanation, और FAQs — सब कुछ एक ही जगह मिलेगा।

Find Greatest of Three Numbers in C — पूरी जानकारी

C language में numbers को compare करना एक foundational skill है। जब हम find greatest of three numbers in C program की बात करते हैं, तो हम basically सीखते हैं कि कैसे if-else conditions का use करके logic build किया जाता है। यह concept आगे चलकर sorting algorithms, data processing, और decision-making programs में काम आता है।

Program Statement

C में एक program लिखिए जो user से तीन integer numbers input ले और उनमें से greatest (सबसे बड़ा) number display करे।

Conditions:

  • अगर तीनों numbers equal हों → “All numbers are equal” display करो
  • अगर पहला number सबसे बड़ा हो → पहला number display करो
  • अगर दूसरा number सबसे बड़ा हो → दूसरा number display करो
  • अगर तीसरा number सबसे बड़ा हो → तीसरा number display करो

Program Code

#include <stdio.h>

int main() {
    int a, b, c;

    // Take three numbers as input
    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    // Check whether all three numbers are equal
    if (a == b && b == c) {
        printf("\nAll three numbers are equal.\n");
    }
    // Check whether 'a' is the greatest
    else if (a >= b && a >= c) {
        printf("\nGreatest number is: %d\n", a);
    }
    // Check whether 'b' is the greatest
    else if (b >= a && b >= c) {
        printf("\nGreatest number is: %d\n", b);
    }
    // Otherwise, 'c' is the greatest
    else {
        printf("\nGreatest number is: %d\n", c);
    }

    return 0;
}

Program Output

▶️ Output Result
Enter three numbers: 45 82 37 Greatest number is: 82 Enter three numbers: 10 10 10 All three numbers are equal.

Step-by-Step Program Explanation

अब हम इस program को line-by-line समझते हैं ताकि find greatest of three numbers in C की पूरी logic आपको crystal clear हो जाए।

1. Header File

#include <stdio.h>

  • यह Standard Input-Output library है।
  • printf() और scanf() functions इसी library से आते हैं।
  • इसके बिना input/output operations possible नहीं होते।

2. Variable Declaration

int a, b, c;

  • तीन integer variables declare किए गए हैं — a, b, और c।
  • यह तीनों variables user द्वारा दिए गए तीन numbers store करेंगे।
  • int data type इसलिए use किया क्योंकि हम whole numbers (integers) के साथ काम कर रहे हैं।

3. User Input लेना

printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
  • printf() → screen पर message display करता है, जो user को बताता है कि input क्या देनी है।
  • scanf() → user द्वारा type किए गए तीनों numbers को एक साथ read करता है।
  • %d → integer format specifier है।
  • &a, &b, &c → इन variables के memory addresses हैं जहाँ values store होती हैं।

4. Equal Numbers Check

if (a == b && b == c)
{
	printf("\nAll three numbers are equal.");
}
  • सबसे पहले यह check किया जाता है कि क्या तीनों numbers equal हैं।
  • == operator से values compare होती हैं।
  • && (Logical AND) का मतलब है — दोनों conditions एक साथ true होनी चाहिए।
  • अगर a == b और b == c दोनों true हैं, तो automatically a == c भी true होगा।

5. First Number Greatest Check

else if (a >= b && a >= c)
{
	printf("\nGreatest number is: %d", a);
}

अगर a दोनों b और c से greater than या equal है, तो a सबसे बड़ा है।

>= operator greater than or equal to check करता है।

यहाँ && ensure करता है कि a का दोनों से comparison एक साथ true हो।

6. Second Number Greatest Check

else if (b >= a && b >= c)
{
	printf("\nGreatest number is: %d", b);
}
  • अगर b दोनों a और c से बड़ा या equal है, तो b greatest number है।
  • यह condition तभी check होती है जब ऊपर वाली conditions false हों।

7. Third Number Greatest (Default Case)

else
{
	printf("\nGreatest number is: %d", c);
}
  • अगर ऊपर की कोई भी condition true नहीं हुई, तो c automatically greatest होगा।
  • यह else block default case की तरह काम करता है।

Alternative Method — Nested If-Else से Find Greatest of Three Numbers in C

#include <stdio.h>

int main() {
    int a, b, c, greatest;

    // Take three numbers as input
    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    // Check whether all three numbers are equal
    if (a == b && b == c) {
        printf("All three numbers are equal.\n");
    }
    else {
        // Compare a with b and c
        if (a > b) {
            if (a > c)
                greatest = a;
            else
                greatest = c;
        }
        // Compare b with c
        else {
            if (b > c)
                greatest = b;
            else
                greatest = c;
        }

        printf("Greatest number is: %d\n", greatest);
    }

    return 0;
}
▶️ Output Result
Enter three numbers: 45 82 37 Greatest number is: 82Enter three numbers: 10 10 10 All three numbers are equal.

यह nested if-else approach भी उतना ही effective है। इसमें पहले a और b को compare करते हैं, फिर winner को c से compare करते हैं।

Ternary Operator से Greatest Number Find करना

C में एक और elegant तरीका है — ternary operator का use:

#include <stdio.h>

int main() {
    int a, b, c, greatest;

    // Take three numbers as input
    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    // Find the greatest number using nested ternary operators
    greatest = (a > b)
                   ? ((a > c) ? a : c)
                   : ((b > c) ? b : c);

    // Display the greatest number
    printf("\nGreatest number is: %d\n", greatest);

    return 0;
}
▶️ Output Result
Enter three numbers: 45 82 37 Greatest number is: 82
  • ? : ternary operator एक short-form if-else की तरह काम करता है।
  • यह method code को compact बनाती है लेकिन beginners के लिए थोड़ी complex लग सकती है।

Common Mistakes जो Beginners करते हैं

जब students find greatest of three numbers in C program लिखते हैं, तो कुछ common errors होती हैं:

  • = और == का confusion — = assignment है, == comparison। गलत use करने पर logic fail हो जाती है।
  • & को scanf में भूलनाscanf(“%d”, a) की जगह scanf(“%d”, &a) लिखना जरूरी है, नहीं तो program crash हो सकता है।
  • Float numbers handle न करना — अगर decimal numbers compare करने हों तो int की जगह float use करें और %f format specifier।
  • सिर्फ > use करना >= की जगह — Equal numbers के case में wrong output आ सकता है।

Real-Life Applications

  1. Find greatest of three numbers in C सिर्फ एक academic exercise नहीं है। इसके practical uses हैं:
  2. Student grade comparison — तीन subjects में highest marks find करना।
  3. Sales data analysis — तीन months में best sales figure identify करना।
  4. Game scoring — तीन players में winner determine करना।
  5. Temperature monitoring — दिन के तीन readings में peak temperature find करना।

Conclusion ( निष्कर्ष )

इस blog में हमने Find Greatest of Three Numbers in C को तीन अलग-अलग approaches — simple if-else, nested if-else, और ternary operator — के साथ detail में समझा। साथ ही हमने program की हर line का explanation, common mistakes, और real-life applications भी cover किए। यह concept C programming की नींव है और इसे अच्छी तरह समझना आपको आगे के complex programs के लिए तैयार करता है।

अब आपकी बारी है — program को अपने system पर run करें, अलग-अलग inputs से test करें, और खुद से modify करके देखें। अगर कोई doubt हो या आप किसी और C programming topic पर guide चाहते हैं, तो नीचे comment करें। हमारे और C programming tutorials पढ़ने के लिए blog को bookmark करना न भूलें!

Frequently Asked Questions

Q 1: Find Greatest of Three Numbers in C में कौन सा approach सबसे अच्छा है?
Ans: Beginners के लिए simple if-else approach सबसे अच्छी है क्योंकि यह readable और समझने में आसान है। जैसे-जैसे आप advanced होते हैं, nested if-else या ternary operator भी use कर सकते हैं। सभी approaches correct results देती हैं, बस code style और complexity अलग होती है।
Q 2: क्या यह program negative numbers के साथ भी काम करता है?
Ans: हाँ, बिल्कुल। C में int data type negative numbers को भी store कर सकता है। अगर आप -5, -2, -9 input करें, तो program correctly -2 को greatest बताएगा क्योंकि number line पर -2 सबसे बड़ा है।
Q 3: अगर तीनों numbers equal हों तो क्या होगा?
Ans: हमारे program में इस case को handle किया गया है। if (a == b && b == c) condition से equal numbers detect होती हैं और “All three numbers are equal” display होता है। अगर यह check न हो, तो भी program technically पहले number को greatest बता देता, जो technically incorrect नहीं होता लेकिन misleading जरूर होता।
Q 4: क्या इस program को तीन से ज्यादा numbers के लिए modify किया जा सकता है?
Ans: हाँ। चार या पाँच numbers के लिए आप additional variables और conditions add कर सकते हैं। लेकिन बड़ी संख्या में numbers के लिए arrays और loops का use करना ज्यादा practical और efficient होता है। उस approach में आप एक loop में सभी numbers को iterate करके maximum find करते हैं।
Q 5: float numbers के लिए यह program कैसे modify करें?
Ans: बस int को float से replace करें और %d को %f से: float a, b, c; scanf(“%f %f %f”, &a, &b, &c); printf(” Greatest number is: %.2f”, greatest); %.2f दो decimal places तक output display करेगा।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top