program to check wheather a number is even or odd in c programming
Conditional statements in C allow you to execute different blocks of code based on whether a certain condition is true or false. The most commonly used conditional statement is the "if-else" statement.
It's used to execute a block of code if a condition is true. For example:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("The number is even.\n");
return 0;
}
It's used to execute one block of code if a condition is true and another block if it's false. For example:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("The number is even.\n");
else
printf("The number is odd.\n");
return 0;
}
It's used to check multiple conditions one by one. The first condition
that is true will execute its corresponding block of code. For example:
this is example of question going to show how to use else- if statement
here is question to check wheather a number is positive or negative
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &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;
}