This program segment below uses a straight-forward approach to count the number of odd and even digits in a given integer number(num).
Initially, variables nodd and neven, the counts for odd and even digits, respectively, are initialized to zero. Then a while loop is used to count the odd and even digits. In each iteration of this loop, the least significant number first determined in the variable digit. The appropriate counter incremented using an if-else statement, and the least significant digit removed from number num. The loop executed as long as the value of num is greater than zero, i. e., all digits in num are not processed. Finally, the values of nodd and never printed.
#include<stdio.h> void main() { int nodd,neven,num,digit; clrscr(); printf("Count number of odd and even digits in a given integer number "); scanf("%d",&num); nodd = neven =0; /* count of odd and even digits */ while (num > 0) { digit = num % 10; /* separate LS digit from number */ if (digit % 2 == 1) nodd++; else neven++; num /= 10; /* remove LS digit from num */ } printf("Odd digits : %d Even digits: %d\n", nodd, neven); getch(); }