C program to find how many even/odd numbers

Problem statement

Write a program to take a input number N and find how many even numbers between 0 to N.

How to find even numbers?

A number which is divisible by 2 is called even number.
An integer that is not an even number is an odd number.
Generally, the last digit of even number is 0, 2, 4, 6 or 8.

Program to find even numbers

Output

Explanation:

In above program, first of all, we take a number i.e. 20 as an input from the user.
We are going to print all even numbers from 0 to input number i.e. 20.
Here for looping, we use for loop.
The for loop will give us one by one number like 1,2,3… up to limit i.e.20.
So we are going to check each number one by one by using control statement if.
if is used to check given number is even or not.
If a number is even it get print otherwise next number will check.
In this way, we will get a list of all even numbers up to 20.

 
 
 

Program to find odd numbers

Output

Ankit Wasankar

Senior Java Developer
Java 11 | Microservices | Reactjs | SQL

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.