more complex decision making c language in hindi.

more complex decision making c language in hindi

more complex decision making c language in hindi

हेल्लो दोस्तों आज आप इस पोस्ट में जानने वाले है (more complex decision making) का c language में उपयोग कब और क्यों करते है | जब किसी प्रोग्राम में एक से अधिक टास्क में से किसी एक टास्क को चुनना होता है तो इसके लिए डिसिशन मेकिंग स्टेटमेंट लिखने की आवश्यकता होती है। जेसे मान लेते है की आपके टीचर आपसे बोलते है| की आप एग्जाम में अगर टॉप करोगे तो ही आपको maths मिलेगा other wise आपको other subject लेना होगा | यानी मेरे बोलने का मतलब ये है की यहाँ एक condition लगा दी जाती है की कितनी% पर कोन सा subject लिया जाना चाहिए |इसी तरह c प्रोग्रामिंग में भी decision making condition होती है|

C प्रोग्रामिंग लैंग्वेज में नॉन जीरो या non-null वैल्यू का अर्थ होता है true और जीरो या null वैल्यू का अर्थ होता है false । C  जितने तरह के डिसिशन मेकिंग स्टेटमेंट सपोर्ट करता हैं वो सभी नीचे टेबल में दिए गए हैं ।

Boolean Expression – बूलियन एक्सप्रेशन वो एक्सप्रेसशन होता है जिसका रिजल्ट true या false में ही हो सकता है ।

Syntax

if(condition)

{

  statement(s);

  }

  else

  {

    statement(s);

    }

Statement & Description:-

1. if statement

Example:-

// C program to illustrate If statement
#include <stdio.h>
int main() {

    int i = 10;

    if (i > 15)

    {

       printf("10 is less than 15");

    }    

    printf("I am Not in if");

    }

Output:-

I am Not in if
--------------------------------
Process exited after 0.02462 seconds with return value 14
Press any key to continue . . .

2. if else-if Ladder statement

Syntax 

if (condition)

{

    // Executes this block if

        // condition is true

        }

        else

        {

            // Executes this block if

                // condition is false

                }

Example:-

#include <stdio.h>

int main() {

    int i = 20;

    if (i < 15){

        printf("i is smaller than 15");

    }

    else{

        printf("i is greater than 15");

    }        

    return 0;    

    }

Output:-

i is greater than 15
--------------------------------
Process exited after 0.02499 seconds with return value 0
Press any key to continue . . .

3. switch-case statements

Syntax

switch (expression){

case value1 :

statement1 ;

break;

case value2 :

statement2 ;

break;

default :

statement3 ;

}

Example:-

#include <stdio.h>
 
#include <conio.h>
 
int main()
 
{
 
int number;
 
printf("Enter a number : ");
 
scanf("%d",&number);
 
switch(number)
 
{
 
     case 1:
 
     printf("First Case");
 
      break;
 
        case 2:
 
        printf("Second Case");
 
          break;
 
            default:
 
           printf("Default Case");
 
              break;
 
                      }
 
                  return 0;
 
                     }

Output:-

Enter a number : 2
Second Case
--------------------------------
Process exited after 2.535 seconds with return value 0
Press any key to continue . . .

4.nested switch statements

नेस्टेड if की ही तरह एक स्विच स्टेटमेंट के अंदर जब एक या अधिक स्विच स्टेटमेंट लगाएं जाते हैं तो उसे nested switch statements कहते हैं ।

Syntax

switch(ch1) {

   case 'A': 
      printf("This A is part of outer switch" );
		
      switch(ch2) {
         case 'A':
            printf("This A is part of inner switch" );
            break;
         case 'B': /* case code */
      }
	  
      break;
   case 'B': /* case code */
}

Example:-

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 100;
   int b = 200;
 
   switch(a) {
   
      case 100: 
         printf("This is part of outer switch\n", a );
      
         switch(b) {
            case 200:
               printf("This is part of inner switch\n", a );
         }
   }
   
   printf("Exact value of a is : %d\n", a );
   printf("Exact value of b is : %d\n", b );
 
   return 0;
}

Output:-

This is part of outer switch
This is part of inner switch
Exact value of a is : 100
Exact value of b is : 200

--------------------------------
Process exited after 0.02638 seconds with return value 0
Press any key to continue . . .

इस पोस्ट में बस इतना ही हम अगले टॉपिक पर नेक्स्ट पोस्ट में बात करेंगे | आप साथ ही साथ पुराणी पोस्ट भी पढ़ कर अपना अब्यास जारी रख सकते है जिससे आपको c language के आने वाले टॉपिक अच्छे से समझ आयेंगे और आपको c language और भी ज्यादा आसान लगेगी | इसी तरह पढ़ते रहे और इस वेबसाइट को follow जरुर कर ले जिससे हमारी आने वाली पोस्ट आप तक सबसे पहले पहुचे | धन्यवाद |

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here