C++ Display all divisors of a number.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main(){
cout << "Enter a number: "; int num; cin >>num;
for (int i = 2 ; i < num; i++){
if (num % i == 0){
cout << i << endl;
}
}
return 0;
}
A divisor, also called a factor, of a number is a number which divides that number completely (such that there is no remainder). You are required to write a program that finds the number (in the given range) which has maximum number of divisors. The program first asks the user to input two values P and Q for a range (where p < Q). After that, the program should find a number having highest number of divisors. In the end, the program should print that numbers (having highest number of divisors) along its divisor count.
ReplyDeleteSample Inputs:
Enter first number (P): 1
Enter second number (Q): 10
Sample Output: 6 has maximum of 4 divisors.(help me making this one)