Notes in Hindi

Introduction to Conditional Statement in Hindi

/ BCA / Programming with C and CPP

Conditional Statement in C Language in Hindi

Introduction to Conditional Statement in Hindi

C language में किसी भी program के अंदर ऐसे बहुत से मौके आते हैं जहाँ हमें किसी condition के base पर decision लेना होता है। जैसे – अगर student के marks 40 से ज्यादा हैं तो "Pass" दिखाओ वरना "Fail" दिखाओ। ऐसे निर्णय लेने के लिए हम Conditional Statements का इस्तेमाल करते हैं।

Conditional Statements वो statements होती हैं जो किसी condition के true या false होने पर program का flow तय करती हैं। इससे हम program को dynamic और logical बना सकते हैं।

Why Conditional Statement is needed?

  • Program को real-world conditions के अनुसार execute करने के लिए।
  • Decision making logic बनाने के लिए।
  • Program को user input के अनुसार flexible बनाने के लिए।

Types of Conditional Statement in C in Hindi

C language में मुख्यतः 4 प्रकार के conditional statements होते हैं:

1. if Statement

अगर कोई condition true होती है, तो block के अंदर का code चलेगा, वरना skip हो जाएगा।

if(condition) { // code block }

2. if-else Statement

अगर condition true है तो एक block चलेगा, नहीं तो दूसरा block execute होगा।

if(condition) { // true block } else { // false block }

3. else-if Ladder

Multiple conditions check करने के लिए use होता है। अगर पहली condition false हो जाती है तो अगली condition check होती है।

if(condition1) { // block 1 } else if(condition2) { // block 2 } else { // default block }

4. Nested if Statement

जब एक if के अंदर दूसरा if use किया जाए, तो उसे nested if कहते हैं।

if(condition1) { if(condition2) { // nested block } }

Use Cases of Conditional Statement in Hindi

Conditional Statements का उपयोग बहुत से real-life scenarios में किया जाता है। कुछ common उपयोग नीचे दिए गए हैं:

  • Result Calculation: Student के marks के अनुसार pass/fail दिखाना।
  • Menu Driven Program: User input के अनुसार operation perform करना।
  • Login Validation: Username/password check करना।
  • Bill Calculation: किसी शॉप पर discount लगाना अगर amount ₹500 से ज्यादा है।
  • Age Based Decision: अगर user की उम्र 18 से ऊपर है तो vote की अनुमति देना।

Example: Simple if Statement

int marks = 75; if (marks > 40) { printf("Pass"); }

Example: if-else Statement

int marks = 35; if (marks >= 40) { printf("Pass"); } else { printf("Fail"); }

Example: else-if Ladder

int marks = 85; if (marks >= 90) { printf("Grade A+"); } else if (marks >= 75) { printf("Grade A"); } else if (marks >= 60) { printf("Grade B"); } else { printf("Fail"); }

Importance of Conditional Statement in Programming in Hindi

Programming में Conditional Statements का बहुत बड़ा महत्व होता है क्योंकि ये program को "smart" बनाते हैं। नीचे कुछ key महत्व दिए गए हैं:

  • Decision Making: Program खुद तय करता है कि कौन सा block चलाना है।
  • Control Flow: ये program के flow को condition के अनुसार बदलता है।
  • Logic Building: Complex logic implement करने के लिए जरूरी है।
  • User Interaction: User input के अनुसार सही output देने में मदद करता है।
  • Error Handling: गलत input मिलने पर alternate output दिखा सकते हैं।

Real Life Example:

मान लीजिए आप एक ATM बना रहे हैं। अगर user का PIN सही है तो balance दिखाएं वरना "Incorrect PIN" दिखाएं। ये सब conditional logic से ही possible होता है।

ATM PIN Example

int pin = 1234; int enteredPin; printf("Enter your PIN: "); scanf("%d", &enteredPin); if (enteredPin == pin) { printf("Access Granted"); } else { printf("Incorrect PIN"); }

Grade System Table

Marks Range Grade
90 - 100 A+
75 - 89 A
60 - 74 B
40 - 59 C
Below 40 Fail

इस प्रकार, conditional statements किसी भी language में एक महत्वपूर्ण आधार होते हैं जो program को logic और decision की शक्ति देते हैं। C language में इनका सही उपयोग करने से आपके programs real-world की problems को बहुत आसानी से solve कर सकते हैं।

Please Give Us Feedback