C program to print even and odd numbers using while loop

In this program, we are going to find out and print even or odd numbers using while loop. We have already covered another similar example for even or odd numbers.

Pre-requisites:

While loop, input output statements, if else statement

Approach:
We will take input from user through command prompt and use it as limit. Limit means range from 0 to input number provided so that we will find even odds from 0 to limit.

Next, we will check whether number is even value by doing modulo division of number by 2. Counter variable i will represent input from 0 to limit and will be modulo divided by 2 and if result is zero i.e. we get no remainder from operation then number is even else it is odd. we will put this condition in if statement condition and when body of it statement executes then printf statement inside it will echo message that number is even.

When if statement condition fails then else statement body will print message that number is odd. After closing if else body, counter variable i is incremented so that loop iterates till maximum number.

Program:

Output:

Leave a Reply

%d bloggers like this: