Definition:
The if-else statement is used to execute one block of code when a condition is true and another block of code when the condition is false. It helps in making decisions based on the given condition.
Explanation: This program accepts a number from the user and determines whether it is even or odd using the if-else statement.
#include <stdio.h> #include <conio.h> main() { int no; clrscr(); printf("Enter the Number : "); scanf("%d",&no); if(no % 2 == 0) { printf("\nThe Number is Even"); } else { printf("\nThe Number is Odd"); } getch(); }
Output:
if-else statement.%) operator with the if-else statement.5 is 0, then the number is divisible by 5.
#include <stdio.h> #include <conio.h> main() { int no; clrscr(); printf("Enter the Number : "); scanf("%d",&no); if(no % 5 == 0) { printf("\nNumber is Divisible by 5"); } else { printf("\nNumber is Not Divisible by 5"); } getch(); }
%) operator to check whether it is divisible by 5. If the remainder is 0, it displays "Number is Divisible by 5"; otherwise, it displays "Number is Not Divisible by 5".