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

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

24 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

24 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

3 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

3 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months 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