Looking for some possible ways to code this in C++, just want a referral so I ca
ID: 3884897 • Letter: L
Question
Looking for some possible ways to code this in C++, just want a referral so I can use to check my progress. Any inquires about the code, leave it in the answer and I will respond.
Input: . Input is a single, positive integer that is 1 or greater. Output for each test case will be: If the input is 0 or less, then the word "Error" is printed and processing ends. · If no error, then you must determine if the input is highly composite If it is highly composit of divisors. For 12, the output would be True Ifit is not highly composite, print "False", a space, the input number, a space, the first number in the sequence 1 to input that has the same number of divisors, a space, and the count of the smaller number's divisors. For 20, the output would be False 20 12 6 on a single line. 20 has 6 divisors (1, 2, 4, 5, 10, 20) but 12 was the first number in the sequence 1 to 20 with 6 divisors. o e, print "True", a space, the input number, a space, and the count 12 6 on a single line. oExplanation / Answer
#include<iostream>
using namespace std;
int main(){
int n,max,num;
int count;
cout << "Enter number :"<< endl;
cin >> n;
if (n <=0){
cout << "Error" << endl;
}
else {
max = 0; // This holds the maximum number of divisors as we go from 1 to n-1, num is the number with maximum
//number of divisors. So the loop is running from 1 to n-1 finding the number with maximum number of
//divisors. Then it compares the max with the number of divisors for the imput n. Bassed on that it gives the
// output. The first loop iterates for numbers 1 to n-1 where as the inner for loop finds the number of divisors
// going from 1 to i-1
num = 0;
for (int i = 1; i<n; i++){
count = 0;
for (int j=1; j<=i; j++){
if (i % j == 0){
count++;
}
}
if (count > max){
max = count;
num = i;
}
}
int count1 = 0;
for (int i = 1; i<=n; i++){
if (n %i == 0)
count1++;
}
cout << count << " " << count1 << endl;
if (count1 > max){
cout << "True " << n << " " << count1 << endl;
}
else {
cout << "False " << n << " " << num << " " << max << endl;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.