How to check if total odd digits in an integer is odd with C

1 Answer

0 votes
#include <stdio.h>
#include <stdbool.h>
 
bool TotalOddAreOdd(int n) {
    int odd = 0;
    
    while (n > 0) {
        int reminder = n % 10;
        if (reminder % 2 != 0)
            odd++;
        n = n / 10;
    }
     
    if (odd % 2 != 0)
        return true;
    else
        return false;
}
  
int main()
{
    int n = 19078342;
     
    if (TotalOddAreOdd(n))
        puts("yes");
    else
        puts("no");
     
    return 0;
}
 
 
 
 
/*
run:
 
no
 
*/

 



answered Sep 8, 2021 by avibootz
edited Sep 8, 2021 by avibootz
...