Odd numbers are integers that are not divisible by 2. Example: 1, 7, -11 , 15
Input: 10 Output: Even
Find all factors of n and then check whether the total number of factors is even or odd. To do this, find all the factors and calculate the quantity, then divide this quantity by 2 to check if it is even or odd.
#include <iostream> #include <math.h> using namespace std; int main() { int n=10; int count = 0; for (int i = 1; i <= sqrt(n) + 1; i++) { if (n % i == 0) count += (n / i == i) ? 1 : 2; } if (count % 2 == 0) printf("Even</p><p>"); else printf("Odd</p><p>"); return 0; }
The above is the detailed content of C program to check if the number of divisors is even or odd?. For more information, please follow other related articles on the PHP Chinese website!