हिंदी माध्यम नोट्स
Switch Statement : Examples in c language in hindi , what is switch statement in c , स्विच स्टेटमेंट क्या है हिंदी में पढ़े
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 to calculate profit or loss.
इस उदाहरण मे , profit और loss को calculate करना है |
Explanation
1.सबसे पहले use से cost price और selling price को input करवाते है |
2. उसके बाद , यूजर से choice input करते है | (i) अगर profit calculate करते है तब ‘P’ input करते है और (ii) अगर loss calculate करना है तब ‘L’ input करवाते है |
2.अगर user द्वारा ‘P’ input करते है तब profit =selling price – cost price को calculate करता है |
3.अगर यूजर द्वारा “L” input करते है तब 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;
char choice;
printf(“Enter Selling Price”);
scanf(“%d”,&sp);
printf(“Enter cost Price”);
scanf(“%d”,&cp);
printf(“Enter Your Choice \n For Profit , enter ‘P’ or For Loss , enter ‘L'”);
scanf(“%c”,&choice);
switch(choice)
{
case ‘P’ :
profit=sp-cp;
profit_per=(profit/cp)*100;
printf(“Profit : %d “, profit);
printf(“Profit In percentage : %f”,profit_per);
break;
case ‘L’ :
loss=cp-sp;
loss_per=(loss/cp)*100;
printf(“Loss : %d”,loss);
printf(“Loss in percentage : %f “,loss_per);
break ;
default:
printf(“You put wrong choice.”);
}
getch();
}आउटपुट होगा :
Enter Selling Price 2000
Enter cost Price 1600
Enter Your Choice
For Profit , enter ‘P’ or For Loss , enter ‘L’ : P
Profit : 400
Profit In percentage : 25
उदाहरण 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;
switch(d>0)
{
case ‘1’ :
r1=(-b+sqrt(d))/(2*a);
r1=(-b-qrt(d))/(2*a);
printf(“Roots Are Positive”);
printf(“%f %f”, r1, r2);
break;
case ‘0’ :
switch(des==0)
{
case ‘1’:
r1=r2=-b/(2*a);
printf(“Both roots of equation are same”);
printf(“%f”,r1);
break;
case ‘0’:
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);
break;
}
}
getch();
}
int a,b,c;
case ‘1’ :
break;
}
int a,b,c;
case ‘1’ :
break;case ‘0’ :
break;
char a;
case ‘a’ :
case ‘e’ :
case ‘i’ :
case ‘o’:
case ‘u’:
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
default :
इन उदहारण से switch statement को और अच्छी तरह से read कर लिया है |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
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 ,…