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

Write a complete C++ program that will do both of the following tasks. Ask the u

ID: 3669446 • Letter: W

Question

Write a complete C++ program that will do both of the following tasks.

Ask the user to enter an integer in the range of 100 to 10,000,000. Read in the input. If the user value is not in the right range, then write out an error message and repeat the process until the user enters an acceptable value.

Find and output the largest integer whose factorial value is less than or equal to m, where m is the user input value from the previous loop. For example, if the user entered 1000, then 6, which has a factorial of 720, is the largest integer, since 7! is greater than 1000.

Explanation / Answer

#include <iostream>

using namespace std;

int fact(int n)
{
int i = n;
while(--n)
    i *= n;

return i;

}

int main()
{
int i,n;
    cout<<"Enter number between 100 and 10,000,000::";
    cin>>n;
    if(n<100||n>10000000)
      {
        printf("Error: Please enter between 100 and 10,000,000 ");
        return 0;
      }

    for(i=1;i<n;i++)
      if(fact(i)<=n&&fact(i+1)>n)
        {
          cout<<"Largest number whose factorial is <= "<<n<<" is "<<i<<endl;
          break;
        }

    return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote