Program to find even and odd digits of a number.

In this program, we have to find the total number of even and odd digits of the given number.

#include<stdio.h>

int main()
{
 int n,d,even=0,odd=0;
 
 printf("Enter a number : ");
 scanf("%d",&n);
 
 while(n>0)
 {
   d =  n % 10;
   
   if(d % 2 == 0)
     even++;
   else
     odd++;
 
  n = n / 10;
 }
 
 printf("Total number of even and odd digits in the number are : \n");
 printf("Even : %d , Odd : %d \n",even,odd); 
 

 return 0;
}
OUTPUT: 
Enter a number : 14523
Total number of even and odd digits in the number are :
Even : 2 , Odd : 3

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *