Write a function called counts that takes as an integer n th

Write a function called counts() that takes as an integer n, the function counts and returns the number of even digits and the number of odd digits in n. write a program to test your function. For example: For n = 348265, the function returns 4 2 to be printed in main() (shown below as well). Enter an integer number n: 328265 The number of Even digits is 4 The number of odd digits is 2 Process returned 0 execution time: = 4.762 s Press any to continue. Write your function below:

Solution


int counts(int,int);

int main()
{
int nodd,neven,num,digit ;

cout<<\"Enter Integer Number : \';

cin >> num;

int counts(int n1,int n2)
{

nodd = neven =0;

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 */

}

return counts;

}

 Write a function called counts() that takes as an integer n, the function counts and returns the number of even digits and the number of odd digits in n. write

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site