# C Program to Count Even, Odd and Zero Digits in a Number

## 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.

### 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

1. Read any number from the console through the keyboard. Suppose that number is stored in the variable num.
2. We need to separate each and every digit. So we will use the modulo operator to find the remainder.
3. Find the remainder by dividing the number by 10 ( Say rem=num%10 )
4. Now, check whether the value of that remainder is Zero or Even or Odd.
5. Divide the same number by 10 to get the quotient ( num=num/10 )
6. Now, repeat steps 3, 4 and 5 until the value of the variable num is greater than zero.

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.