हिंदी माध्यम नोट्स
If-Else (Most Important Examples) in c language in hindi , इफ एल्स क्या है c भाषा में हिंदी 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();
}
int a,b,c;
if(b+c)>a)
count =1;
else
int a,b,c;
else
char a;
else
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…