https://github.com/mashrafigit/practice-task-operators-conditional-statements
https://github.com/mashrafigit/practice-task-operators-conditional-statements
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mashrafigit/practice-task-operators-conditional-statements
- Owner: MashrafiGit
- Created: 2025-04-08T12:51:47.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-04-08T13:31:46.000Z (7 months ago)
- Last Synced: 2025-04-08T14:33:00.037Z (7 months ago)
- Language: C
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## #Practice Task of Operators-Conditional-Statements
1. Take a number from user and check if its a even number or odd number.
2. Take a number from user and check if its a positive or negative number.
3. Explain if else ladder.
---
### Answer:
1. Go to the > `even_odd.c` file.
2. Go to the > `positive_negative.c` file.
3. An `if-else` ladder is a series of `if-else` statements that are used when we have multiple conditions to check. It's essentially a chain of if statements followed by corresponding `else if` statements and ending with a final else block to handle any condition that doesn't match the previous ones.
In an `if-else` ladder, only one block of code gets executed, based on the first condition that is true. If no condition is true, the final else block (if present) will be executed.
Example of `if-else` ladder:
```c
#include
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
// Using if-else ladder to check the value of num
if (num > 0) {
printf("The number is positive.\n");
} else if (num < 0) {
printf("The number is negative.\n");
} else {
printf("The number is zero.\n");
}
return 0;
}
```