đ if Condition in C Programming
đ Short Explanation:
In C, the if statement is used to make decisions. It checks a condition—if it's true, the code inside runs. Otherwise, it’s skipped.
It helps control the program’s flow based on logic and input.
✅ Basic Syntax
if (condition) {
// code to execute if condition is true
}
đ§Ē Example: Simple if Statement
#include <stdio.h>
int main() {
int age = 20;
if (age >= 18) {
printf("You are eligible to vote.\n");
}
return 0;
}
đ§ Output:
You are eligible to vote.
đ if-else Syntax
if (condition) {
// runs if true
} else {
// runs if false
}
đ Example:
int number = 5;
if (number % 2 == 0) {
printf("Even number\n");
} else {
printf("Odd number\n");
}
đ if-else if-else Ladder
if (condition1) {
// block 1
} else if (condition2) {
// block 2
} else {
// default block
}
đ Example:
int score = 85;
if (score >= 90) {
printf("Grade A\n");
} else if (score >= 80) {
printf("Grade B\n");
} else {
printf("Grade C\n");
}
⚠️ Tips to Remember
- Use
==for comparison, not=. - The condition must return true (non-zero) or false (zero).
- You can use logical operators:
&&(AND),||(OR),!(NOT).
đ Summary
The if statement is the foundation of decision-making in C. It allows your program to respond to conditions, making it flexible and interactive. With if, else, and else if, you can cover all logic scenarios effectively.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ