Odd or Even Program in C Using For Loop

Odd or even program in c using for loop to check the number is divisible by two or not. Using this program we can check the year or number is odd or even using for loop.

For Loop Definition to Execute Odd or Even

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times.

The loop allows us to perform an arbitrary number of steps in a single line.

A for-loop (or simply for loop) is a control flow statement in computer science that specifies iteration and allows code to be executed repeatedly.

The name for-loop comes from the word for, which is used as a keyword to introduce a for-loop in many programming languages.

Odd or Even Definition in C

An even number is a number that can be divided into two equal groups.

An odd number is a number that cannot be divided into two equal groups.

Even numbers end in 2, 4, 6, 8, and zero, regardless of how many digits they have.

#include<stdio.h>
int main()
{
int n,last;
printf("\n Enter Last Number");
scanf("%d",&last);
printf("\n Even Number List\n ");
for(n=2;n<=last;n+=2)
{
printf(" %d",n);
}
printf("\n\n Odd Number List\n ");
for(n=1;n<=last;n+=2)
{
printf(" %d",n);
}
}

Output:

Enter Last Number 5

Even Number List
2 4

Odd Number List
1 3 5