Introduction
In this post, I am going to write a c program to count the number of even, odd and zero digits in a number. That means we will read a single number and then count how many even, odd and zeros are there. See the following expected output.
Also Read: Switch Case in C Program to Calculate Area of Circle and Triangle
Expected Output

From the above expected output, we are reading a single number and counting the even number of digits, odd number of digits and number of zero’s. For this, you need to understand the logic of this program.
Logic of this Program
- Read any number from the console through the keyboard. Suppose that number is stored in the variable num.
- We need to separate each and every digit. So we will use the modulo operator to find the remainder.
- Find the remainder by dividing the number by 10 ( Say rem=num%10 )
- Now, check whether the value of that remainder is Zero or Even or Odd.
- Divide the same number by 10 to get the quotient ( num=num/10 )
- Now, repeat steps 3, 4 and 5 until the value of the variable num is greater than zero.
Also Read: C Program to Print Multiples of 5 using do while loop
I hope you have understood the above steps that we are performing. Now, see the following program.
C Program to Count Even, Odd and Zero Digits in a Number
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,rem,ne=0,no=0,nz=0,anum;
printf("Enter any Number\n");
scanf("%d",&num);
printf("In the given number %d\n",num);
while(num>0)
{
rem=num%10;
if(rem==0)
{
nz++;
}
else if(rem%2==0)
{
ne++;
}
else
{
no++;
}
num=num/10;
}
printf("EVEN number of digits except 0 are %d\n",ne);
printf("ODD number of digits are %d\n",no);
printf("number of ZERO digits are %d\n",nz);
return 0;
}
In the above c program, variables ne, no and nz are used to count the total number of even numbers, odd numbers and zeros respectively in the given number i.e. num.
I hope you have understood this program. If you have any difficulty to understand this program, please feel free to contact me.
Thank you.
Some Important Programs
- C Program to Remove Zeros from a number
- The while loop in C Programming
- Reverse a Number using getchar and putchar function in c
- C Program to Print Numbers Except Multiples of n
- C Program to Remove White Spaces and Comments from a File
- Program in C to Find Longest Line in a File
- Palindrome in C using Pointers
- Insert and Delete element in Array in C using switch case
- C Program to Add Alternate Elements of a 2D Array
- Arrays in C for Complete Beginners
- C Program to Find Area of a Circle using Preprocessor