Skip to main content

C Program to Identify Even Odd numbers from user input.

Below program will first accept total number which user want to enter. Then user has to enter numbers one by one.

Program will identify even and Odd numbers and store their total count in variable.

// Program Name: Accept n numbers from user and then identify even or odd Numbers
#include<stdio.h>
 
void main()
{
 int totalNum, i, ary[100];
 int eNoCnt = 0, oNoCnt = 0;
 
 printf("\n\t Enter the Size of an Array (total numbers)  :  \t");
 scanf("%d", &totalNum);
 
 printf("\n\t Enter the Numbers to identify even numbers\t");
 for(i = 0; i < totalNum; i++)
 {
   scanf("%d", &ary[i]);
 }
  
 for(i = 0; i < totalNum; i ++)
 {
   if(ary[i] % 2 == 0)
   {
     eNoCnt++;
   }
   else
   {
     oNoCnt++;
   }
 }
  
 printf("\n\t Total Number of Even Numbers are = %d ", eNoCnt);
 printf("\n\t Total Number of Odd Numbers are = %d ", oNoCnt);
}


	 Enter the Size of an Array (total numbers)  :  	6



	 Enter the Numbers to identify even numbers	1

2

3

4

5

6



	 Total Number of Even Numbers are = 3 

	 Total Number of Odd Numbers are = 3 

Program to print Odd Numbers till user input

// Program to print odd numbers from 1 to n
#include <stdio.h>
int main() {
    int range;
    printf("Enter range of number to print odd numbers");
    scanf("%d",&range);
      printf("Odd Numbers from 1 to %d are \n",range);
    for(int i =1;i<=range;i++)
    {
        if (i%2 != 0)
        printf("\t%d",i);
    }
    return 0;
}

Output

Enter range of number to print odd numbers   15
Odd Numbers from 1 to 15 are 
	1	3	5	7	9	11	13	15

Program to Print Even Numbers till User Input

// Program to print even numbers from 1 to n
#include <stdio.h>
int main() {
    int range;
    printf("Enter range of number to print even numbers  ");
    scanf("%d",&range);
      printf("Even numbers from  1 to %d are \n",range);
    for(int i =1;i<=range;i++)
    {
        if (i%2 ==  0)
        printf("\t%d",i);
    }
    return 0;
}

Output

Enter range of number to print even numbers  15
Even numbers from  1 to 15 are 
	2	4	6	8	10	12	14