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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> int main() { int N, i=0; printf("\n Provide maximum limit:"); scanf("%d",&N); while(i<=N) { if(i%2==0) { printf("\n even numbers: %d",i); } else { printf("\t odd numbers: %d",i); } i++; } return 0; } |

### Output:

1 2 3 4 5 6 7 |
Provide maximum limit:10 even numbers: 0 odd numbers: 1 even numbers: 2 odd numbers: 3 even numbers: 4 odd numbers: 5 even numbers: 6 odd numbers: 7 even numbers: 8 odd numbers: 9 even numbers: 10 |