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


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

count even odd and zero digits in a number output
Output – count even odd and zero digits in a number

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.

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");
    printf("In the given number %d\n",num);
        else if(rem%2==0)
    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

  1. C Program to Remove Zeros from a number
  2. The while loop in C Programming
  3. Reverse a Number using getchar and putchar function in c
  4. C Program to Print Numbers Except Multiples of n
  5. C Program to Remove White Spaces and Comments from a File
  6. Program in C to Find Longest Line in a File
  7. Palindrome in C using Pointers
  8. Insert and Delete element in Array in C using switch case
  9. C Program to Add Alternate Elements of a 2D Array
  10. Arrays in C for Complete Beginners
  11. C Program to Find Area of a Circle using Preprocessor

Leave a Comment