JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

If-Else (Most Important Examples) in c language in hindi , इफ एल्स क्या है c भाषा में हिंदी decision making statement

इफ एल्स क्या है c भाषा में हिंदी में जाने , If-Else (decision making statement) (Most Important Examples) in c language in hindi :-
इससे पहले Decision making statements को पढ़ा है | C language मे , decision making statement तीन प्रकार के होते है :-
1. if else statement
इस statement से कोई condition check की जाती है |जब condition true होती तब true statement execute होगा |अन्यथा false statement execute होगा |इसका syntax है :-
if(condition)
{
true statement;
{
else
{
false statement;
}
2. Switch statement
जब multiple conditions को check की जाती है तब अलग अलग statement block execute होगी | इसका syntax है :-
switch(condition)
{
case case_label 1:
executable statement;
break;
case case_label 2:
executable statement;
break;
case case_label 3:
executable statement;
break;

default :
exit();
}
3. Looping
जब किसी statement को किसी condition के true करने पर execute करता है |ये तीन प्रकार के होते है |-
(i) while loop
(ii) Do -While loop
(iii)For loop

If-Else Statement examples :

उदहारण -1
Write a c program तो calculate profit or loss.
इस उदाहरण मे , profit और loss को calculate करना है |

Explanation
1.सबसे पहले use से cost price और selling price को input करवाते है |
2.अगर selling price ,cost price से बड़ी होती है तब  profit =selling price – cost price को calculate करता है |
3.अगर selling price ,cost price से छोटी होती है तब  loss= cost price -selling price को calculate करता है |
Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
int sp,cp;
int profit,loss;

float profit_per,loss_per;
printf(“Enter Selling Price”);
scanf(“%d”,&sp);
printf(“Enter cost Price”);
scanf(“%d”,&cp);
if(sp>cp)
{
profit=sp-cp;
profit_per=(profit/cp)*100;
printf(“Profit : %d “, profit);
printf(“Profit In percentage : %f”,profit_per);
}
else
{
loss=cp-sp;
loss_per=(loss/cp)*100;
printf(“Loss : %d”,loss);
printf(“Loss in percentage : %f “,loss_per);
}
getch();
}आउटपुट होगा :
Enter Selling Price 2000
Enter cost Price 1800
Profit : 200
Profit In percentage : 11.11

उदाहरण 2
Write a program to find roots of a quadratic equation.
इस उदहारण मे , किसी quadratic equation के roots को find करने के लिए किया जाता है |

Explanation
Expression : ax^2 + b x + c
1.सबसे पहले discriminant को calculate करते है :- des = b^2 – 4ac
2.अगर des पॉजिटिव होती है तब इसके roots real होते है | इसका formula होता है :-
(-b + squareroot(des )) / 2*a
और
(-b-squareroot(des )) / 2*a
3. अगर des , zero है तब इस exucation के एक ही root होते है|
-(b/2a)
4.अगर des, negative होता है तब root complex number होते है|
in complex numbers का real part होता है :-
-(b/2a)     और  -(b/2a)
और इसके लिए imaginary पार्ट होगा :-
squareroot(des ) /(2*a)

source code
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
float d;
float r1,r2;
float i;
printf(“Enter value of a,b or c”);
scanf(“%d %d %d”,&a, &b,&c);
d=b*b-4ac;
if(d>0)
{
r1=(-b+sqrt(d))/(2*a);
r1=(-b-qrt(d))/(2*a);
printf(“Roots Are Positive”);
printf(“%f %f”, r1, r2);
}
else if (d==0)
{
r1=r2=-b/(2*a);
printf(“Both roots of equation are same”);
printf(“%f”,r1);
}
else
{
r1=r2=-b/(2*a);
i=sqrt(-d)/(2*a);
printf(“Roots are complex number”);
printf (“%f+i %f ,%f – i %f”,r1,i,r2,i);
}
getch();
}

आउटपुट होगा
Enter value of a,b or c 1 8 7
Roots Are Positive
-1.00 -7.00
और
Enter value of a,b or c 1 4 0
Both roots of equation are same
-4.00
उदहारण 3
check validity of triangle by given sides.
इस उदहारण मे, किसी triangle की validity को check करना |
Explanation
1.सबसे पहले किसी triangle की तीनो sides को यूजर से input करा लेते है |
2.उसके बाद अगर ,यूजर द्वारा दिए गयी sides निन्म condition को फॉलो करती है तब triangle possible होगा :-
suppose l,m और n triangle की sides है तब condition
(i) l+m >n
(ii) m+n >l
(iii) l+n> m
3.अन्यथा enter की गयी sides से triangle बनाना impossible है |
source code
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int count =0;
printf(“Enter Sides”);
scnaf(“%d %d %d “,&a &b &c);
if((a+b)>c)
{
if((a+c)>b)
{
if(b+c)>a)
{
count =1;
}
if(count == 1)
{
printf(“Triangle is Possible with these sides value “);
}
else
{
printf(“Triangle is Not Possible with these sides value “);
}
getch();
}
आउटपुट होगा :
Enter Sides 5 4 7
Triangle is Possible with these sides value
उदहारण 3
check validity of triangle by given angels.
इस उदहारण मे, किसी triangle की validity को check करना |अगर यूजर द्वारा angel की value assign की जाती है |
Explanation
1.सबसे पहले किसी triangle की तीनो angel को यूजर से input करा लेते है |
2.उसके बाद condition check की जाती है |अगर तीनो angel का sum 180 नहीं होता तब Triangle is Possible with these angel value. print होगा |
3.अन्यथा Triangle is Possible with these sides value message print होगा  |
source code
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int count =0;
printf(“Enter Angel”);
scnaf(“%d %d %d “,&a &b &c);
if((a+b+c)==180)
{
printf(“Triangle is Possible with these angel value “);
}
else
{
printf(“Triangle is Not Possible with these angel value “);
}
getch();
}
आउटपुट होगा :
Enter Sides 60 50 70
Triangle is Possible with these angel value.
उदहारण 5 :-
check an alphabet is vowel or consonant.
इस उदहारण मे , alphabet के vowel या consonant होने की condition को check करना है |
Explanation
1.सबसे पहले किसी alphabet को यूजर से input करा लेते है |
2.उसके बाद condition check की जाती है |अगर यूजर द्वारा input किया alphabet ‘a’,’e’,’i’,’o’,’u’ और ‘A’ ,’O’,’I’,’U’ ,’E’ है तब alphabet is vowel message आ जायेगा |
3.अन्यथा alphabet is consonant message message print होगा  |
source code
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
int count =0;
printf(“Enter character”);
scnaf(“%c “,&a);
if((a==a|| (a==e)|| (a==i)|| (a==u)||(a==o)|| (a== A) || (a== I) || (a==E) || (a== O) || (a==U) )
{
printf(” Alphabet is Vowel.”);
}
else
{
printf(” Alphabet is consonant.”);
}
getch();
}
आउटपुट होगा :
Enter character i
Alphabet is Vowel.
और
Enter character B
Alphabet is consonant.
Sbistudy

Recent Posts

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

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

21 hours ago

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

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

21 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