if else statement in c in hindi
C में if-else स्टेटमेंट का उपयोग कुछ विशिष्ट conditions के आधार पर संचालन करने के लिए किया जाता है। यदि दिए गए condition true हैं, तो if block में निर्दिष्ट operations निष्पादित किए जाते हैं।
C भाषा में statements के निम्नलिखित प्रकार हैं।
- If statement
- If-else statement
- If else-if ladder
- Nested if
If Statement in c in hindi
यदि if statement का उपयोग किसी दी गई condition की जांच करने और उस condition की correctness के आधार पर कुछ operations करने के लिए किया जाता है। यह ज्यादातर उस परिदृश्य में उपयोग किया जाता है जहां हमें विभिन्न conditions के लिए अलग-अलग ऑपरेशन करने की आवश्यकता होती है। if statement का syntax नीचे दिया गया है।
- if(expression){
- //code to be executed
- }
Flowchart of if statement in C
Let’s see a simple example of C language if statement.
- #include<stdio.h>
- int main(){
- int number=0;
- printf(“Enter a number:”);
- scanf(“%d”,&number);
- if(number%2==0){
- printf(“%d is even number”,number);
- }
- return 0;
- }
Output
Enter a number:4
4 is even number
enter a number:5
Program to find the largest number of the three.
- #include <stdio.h>
- int main()
- {
- int a, b, c;
- printf(“Enter three numbers?”);
- scanf(“%d %d %d”,&a,&b,&c);
- if(a>b && a>c)
- {
- printf(“%d is largest”,a);
- }
- if(b>a && b > c)
- {
- printf(“%d is largest”,b);
- }
- if(c>a && c>b)
- {
- printf(“%d is largest”,c);
- }
- if(a == b && a == c)
- {
- printf(“All are equal”);
- }
- }
Output
Enter three numbers?
12 23 34
34 is largest
If-else statement in C in hindi
If-else स्टेटमेंट का उपयोग किसी एक condition के लिए दो ऑपरेशन करने के लिए किया जाता है। If-else स्टेटमेंट, if स्टेटमेंट के लिए एक एक्सटेंशन है, जिसका उपयोग करके हम दो अलग-अलग ऑपरेशन कर सकते हैं, अर्थात, एक उस condition की correctness के लिए है, और दूसरा condition की incorrectness के लिए है। यहां, हमें ध्यान देना चाहिए कि if और else ब्लॉक को एक साथ निष्पादित नहीं किया जा सकता है। if-else स्टेटमेंट का उपयोग करना हमेशा बेहतर होता है क्योंकि यह हमेशा हर इफ़ेक्ट के साथ एक otherwise case को invoke करता है। If-else स्टेटमेंट का सिंटैक्स नीचे दिया गया है।
if(expression){
//code to be executed if condition is true
}else{
//code to be executed if condition is false
}
Flowchart of the if-else statement in C
Let’s see the simple example to check whether a number is even or odd using if-else statement in C language.
#include<stdio.h>
int main(){
int number=0;
printf("enter a number:");
scanf("%d",&number);
if(number%2==0){
printf("%d is even number",number);
}
else{
printf("%d is odd number",number);
}
return 0;
}
Output
enter a number:4
4 is even number
enter a number:5
5 is odd number
Program to check whether a person is eligible to vote or not.
#include <stdio.h>
int main()
{
int age;
printf("Enter your age?");
scanf("%d",&age);
if(age>=18)
{
printf("You are eligible to vote...");
}
else
{
printf("Sorry ... you can't vote");
}
}
Output
Enter your age?18
You are eligible to vote…
Enter your age?13
Sorry … you can’t vote
If else-if ladder Statement in C in hindi
If-else-if ladder स्टेटमेंट if-else स्टेटमेंट का विस्तार है। इसका उपयोग उस परिदृश्य में किया जाता है जहां विभिन्न conditions के लिए कई मामलों का प्रदर्शन किया जाना है। If-else-if ladder statement में, यदि कोई condition true है, तो if ब्लॉक में परिभाषित statements को निष्पादित किया जाएगा, अन्यथा यदि कोई अन्य condition true है, तो else-if ब्लॉक में defined statements को निष्पादित किया जाएगा। अंत में यदि कोई भी condition true नहीं है, तो else ब्लॉक में परिभाषित statements को निष्पादित किया जाएगा।
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
Flowchart of else-if ladder statement in C
The example of an if-else-if statement in C language is given below.
#include<stdio.h>
int main(){
int number=0;
printf("enter a number:");
scanf("%d",&number);
if(number==10){
printf("number is equals to 10");
}
else if(number==50){
printf("number is equal to 50");
}
else if(number==100){
printf("number is equal to 100");
}
else{
printf("number is not equal to 10, 50 or 100");
}
return 0;
}
Output
enter a number:4
number is not equal to 10, 50 or 100
enter a number:50
number is equal to 50
Program to calculate the grade of the student according to the specified marks.
#include <stdio.h>
int main()
{
int marks;
printf("Enter your marks?");
scanf("%d",&marks);
if(marks > 85 && marks <= 100)
{
printf("Congrats ! you scored grade A ...");
}
else if (marks > 60 && marks <= 85)
{
printf("You scored grade B + ...");
}
else if (marks > 40 && marks <= 60)
{
printf("You scored grade B ...");
}
else if (marks > 30 && marks <= 40)
{
printf("You scored grade C ...");
}
else
{
printf("Sorry you are fail ...");
}
}
Output
Enter your marks?10 Sorry you are fail ... Enter your marks?40 You scored grade C ... Enter your marks?90 Congrats ! you scored grade A ...