Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#6 Write a big.cpp program that does the following: 1. Ask the user to enter a p

ID: 3725699 • Letter: #

Question

#6 Write a big.cpp program that does the following: 1. Ask the user to enter a positive integer with at least 2 digits. 2. If the user enters an invalid input, ask to try again. 3. Print out the biggest integer in the user's number For example, if the user enters 167256.The program prints: 7 #7 Write a factor.cpp program that does the following: 1. Ask the user to enter a 2-digit number, and store it as an int. 2. If the input is not a 2-digit number, repeatedly ask the same question until the user enters a 2-digit number. 3. Print all positive factors of the number, in ascending order, one per line. A number i is a factor of n if when you divide n by i, the remainder is 0. 4. Then print the total number of factors. Example Enter a 2-digit number: 15 Factors: 3 5 15 15 has 4 factors.

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int n;
cout<<"Enter a positive number with 2-digit: "<<endl;
cin >> n;
while(n < 10) {
cout<<"Invalid input. Input must be 2-digit"<<endl;
cout<<"Enter a positive number with 2-digit: "<<endl;
cin >> n;
}

int max = n % 10;
while(n > 0) {
int r = n % 10;
if(max < r) {
max = r;
}
n= n/ 10;
}
cout<<"Max Number: "<<max<<endl;
return 0;
}

Output:

Enter a positive number with 2-digit: 5
Invalid input. Input must be 2-digit: 167256
Enter a positive number with 2-digit:
Max Number: 7

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int n;
cout<<"Enter a positive number with 2-digit: "<<endl;
cin >> n;

while(n<10) {
cout<<"Invalid input. Input must be 2-digit"<<endl;
cout<<"Enter a positive number with 2-digit: "<<endl;
cin >> n;
}
cout<<"Factors:"<<endl;
int count = 0;
for(int i=1;i<=n;i++) {
if(n%i == 0) {
cout<<i<<endl;
count++;
}
}
cout<<n<<" has factors "<<count<<endl;
return 0;
}

Output:

Enter a positive number with 2-digit: 7
Invalid input. Input must be 2-digit
Enter a positive number with 2-digit: 8
Invalid input. Input must be 2-digit
Enter a positive number with 2-digit: 15
Factors:
1
3
5
15
15 has factors 4