Skip to main content

Count The Number of Odd and even Digits in the Given Integer Using Command Line arguments

Source Code:


#include<stdio.h>
#include<stdlib.h>
void main(int argc, char const*argv[])
{
 int oddCount = 0, evenCount = 0, InputNum, temp ;
InputNum = atoi(argv[1]);
 while (InputNum> 0)
        {
             temp = InputNum % 10;                         /* separate Last digit from number */
              if (temp % 2 == 1)
                {
                  oddCount++;
                 }
              else
                  {
                  evenCount++;
                  }
                   InputNum /= 10;                      /* remove Last digit from num */
         }
printf("Number of Odd digits : %d \nNumber of Even digits: %d\n", oddCount, evenCount);

}

Output:

Count number of Odd and Even Digits


Thanks and regards,
Tech Bird

Comments