- If a number is divisible by 2 then it is an even number.
- If a number is not divisible by to it is an odd number.
- To check even or odd number in c we just need to check that using one if condition.
- If if condition of number%2 returns true then it is even number other wise it is odd number.
- Let us see an example c program to check a given number is even or odd without using any recursive function.
Program #1: write a c program to check a number is even or odd without using recursive function.
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv)
- int number;
- printf("Enter a nuber to check even or odd");
- scanf("%d", &number);
- // returns true if number is divisible by 2: even
- if(number % 2 == 0)
- printf("%d is even.", number);
- printf("%d is odd.", number);
Program #2: write a c program to check a number is even or odd without using if condition