Even odd program in c using for loop
Last updated:12th Aug 2022
In this example, you will write a C program to print all even odd numbers within a given number.
for example, if a user enters 3 then print all even or odd within 3.
input: 3 output: 1 is odd 2 is even 3 is odd
Program
#include <stdio.h>
int main() {
int num, i;
printf("Enter an integer number: ");
scanf("%d", & num);
for (i = 1; i <= num; i++) {
if (num % 2 == 0) {
printf("%d is even\n", i);
} else {
printf("%d is odd\n", i);
}
}
return 0;
}
output
Enter an integer number: 5 1 is odd 2 is odd 3 is odd 4 is odd 5 is odd
if a number is divisible by 2 and the remainder is 0 then the number is even
otherwise, a number will be odd
.