JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Decision Making – If Statement in hindi in c language इफ स्टेटमेंट c कंप्यूटर भाषा में

इफ स्टेटमेंट c कंप्यूटर भाषा में Decision Making – If Statement in hindi in c language :-
C Program दो या दो से अधिक statements का  समूह होता है जो sequence से execute होता है |लेकिन कभी कभी प्रोग्रामर को किसी statements को बार बार repeat करना पड़ सकता है या प्रोग्राम के sequenceको change करना पड़ सकता है | इस तरह के operations के लिए C language मे 4 OPTION है |
1. if Statements
2.Switch Statement
3.Conditional Operator Statement
4.Goto Statement


इस article मे if statement को उदहारण के साथ पड़ेगे |if Statement का Usage:
if Statement C language मे सबसे महत्वपूर्ण decision statement है |इससे दो प्रकार के आउटपुट मिलते है |(i) true (ii)false.इसका syntax निम्न है :-

if (condition);

ये कंप्यूटर को पहले condition check करवाता है, बाद मे true और false के हिसाब से satement पर control करता है |

ये चार प्रकार के होते है :-

1.Simple if Statement

Simple if statement मे,अगर condition true होती है तब true statement block execute होता है और false होने पर ,true statement block के बाद वाले Statements execute होते है |इसका structure है :-

if(condition)
{
true statements block ;
}
statements ;

 

उदहारण के लिए :
#include <conio.h>
void main ()
{
int a,b;
printf(“Enter first input”);
scanf(“%d”,&a);
printf(“Enter second input”);
scanf(“%d”,&b);
if (a<b)
{
printf(“%d is bigger than %d .  “,a,b)
}
printf(“%d is bigger than %d .”,b,a)
}


इस उदहारण मे condition सही होने पर a is bigger than b. print होगा और गलत होने पर  b is bigger than a . print होगा |


आउटपुट होगा :-
Enter first input 567
Enter second input 614
614 is bigger than 567 .
और
Enter first input 97
Enter second input 67
97 is bigger than 67 .

if-else Statement :


इस प्रकार मे प्रोग्रामर दो blocks (Group of Statements) बना सकता है एक condition True होने पर execute होगा और दूसरा  condition false होने पर execute होगा |इसका structure निम्न है :-
if (condition)
{
true condition block ;
}
else
{
false condition block;
}
statement ;

उदहारण के लिए :

#include <conio.h>
void main ()
{
int a,b,c;
printf(“Enter first input”);
scanf(“%d”,&a);
printf(“Enter second input”);
scanf(“%d”,&b);
if (a<b)
{
c=b/a;
printf(” output of b/a = %d “,c);
}
else
{
c=a/b;
printf(“output of a/b =%d”,c);
}
printf(“a is same b.”);
}
}
Output होगा :
Enter first input 555
Enter second input 5
output of a/b =111
और
Enter first input 2
Enter second input 666
output of b/a =333
और
Enter first input 235
Enter second input 235
a is same b.

Nested If Else Statement
 जब एक या एक से अधिक  decisions /conditions को check करना हो तब nested if else statement का इस्तेमाल होता है | इसका Structure निन्म है :-
if (condition -1)
{
if ( condition-2)

   {
       True Statement block for if condition-2
   }
Else
   {
      False staement block for if condition-2
   }
}
else 
{
False statements block for if condition-1
}

इस structure मे जब condition-1 गलत होगी तब False statements block for if condition-1 execute होगा |और true होने पर if statement चलेगे जो condition-2 check करेगा |


उदहारण के लिए:
नीचे दिया गया उदहारण मे ,तीन numbers मे से सबसे बड़ी numbers को find करना है जिसमे nested if statement को इस्तेमाल किया गया है |

#include<conio.h>
void main()
{
int a,b,c;
printf(“Enter first input”);
scanf(“%d”,&a);
printf(“Enter second input”);
scanf(“%d”,&b);
printf(“Enter third input”);
scanf(“%d”,&c);
if (a>b)
{
if (a>c)
{
prinf(“\n%d is bigger among them.”,a);
}
else
{
printf(“\n%d is bigger among them.”,c);
}
else
{
if (b>c)
{
printf(“\n%d is bigger among them.”,b);
}
else
printf(“\n%d is bigger among them. “,c);
}
}

इस उदहारण मे,सबसे पहले a का comparison b और c से होता है |सबसे पहले a को b से compare करते है a को  बड़ा होगा तब दुसरे if statement मे  b से compare होगा और true होने पर a is bigger among them. प्रिंट होगा |
पहले if statement मे false होने पर b को c से compare होता है , अगर b बड़ा है तब b is bigger among them. प्रिंट होगा और गलत होने पर c is bigger among them. होगा |

आउटपुट होगा :-

Enter first input 67
Enter second input 95
Enter third input 106

106 is bigger among them.

Else -if Statement

इस structure मे सभी else के साथ एक if statement जुड़ा होता है |इसे else if ladder भी कहते है |उदहारण के लिए :

नीचे दिया गया प्रोग्राम मे ,स्टूडेंट्स के द्वारा दिए गये मार्क्स से चार grade “honours”,”first”,”second” और ”third’ का पता लगाने के लिए है |
#include <conio.h>
void main ()
{
int a,b,c;
printf(“Enter your score”);
scanf(“%d”,&a);
if (a=>80)
{
printf(“Your Grade is honour ! congratulation.”);
}
else if(a=>60)
{
printf(“Your Grade is first division ! congratulation.”);
}
else if (a=>50)
{
printf(“Your Grade is second division ! congratulation.”);

}
else
{

printf(“Your Grade is third division ! congratulation.”);

}
}

आउटपुट होगा :-
Enter your score 67
Your Grade is first division ! congratulation.

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now