

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Program to Check if count of divisors is even or odd?
Given a number “n” as an input, this program is to find the total number of divisors of n is even or odd. An even number is an integer that is exactly divisible by 2. Example: 0, 8, -24
An odd number is an integer that is not exactly divisible by 2. Example: 1, 7, -11, 15
Input: 10 Output: Even
Explanation
Find all the divisors of the n and then check if the total number of divisors are even or odd. To do this find all divisor and count the number and then divide this number by 2 to check if it is even or odd.
Example
#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\n"); else printf("Odd\n"); return 0; }
- Related Questions & Answers
- Java Program to check if count of divisors is even or odd
- Check if count of divisors is even or odd in Python
- Python Program for Check if the count of divisors is even or odd
- PHP program to check if the total number of divisors of a number is even or odd
- C++ Program to Check Whether Number is Even or Odd
- How to Check if a Number is Odd or Even using Python?
- Java Program to Check Whether a Number is Even or Odd
- C# Program to check if a number is Positive, Negative, Odd, Even, Zero
- 8085 program to check whether the given number is even or odd
- Program to check if a number is Positive, Negative, Odd, Even, Zero?
- How to determine if a number is odd or even in JavaScript?
- Java program to find whether given number is even or odd
- Program to find count of numbers having odd number of divisors in given range in C++
- Check whether given floating point number is even or odd in Python
- C++ program for the Array Index with same count of even or odd numbers on both sides?
Advertisements