Hi guys, I'm just working on an assignment and I have no idea where to start. I'm just starting to learn for loops and while loops, can this program be accomplished by nesting one inside the other? I'm not asking anyone to do the assignment for me, I just really don't know where to start.
I appreciate the help but I would have to do it using a loop of some sort and we havent learned factorial() so it would have to be done using a for loop, a do while loop or just a while loop...
Looks OK so the next step is to use that to find the largest value of n which doesn't give a higher factorial than 3000. Maybe loop through n's until you find it? Start at n=1 and keep incrementing n until factorial(n) >= 3000?
//Lab 3-3: Find the smallest integer whose factorial is greater than 3000
#include<iostream>
usingnamespace std;
int factorial(int n);
int main()
{
int fact;
int n = 1;
do{ n++;
fact = factorial(n);
}
while (fact <= 3000);
cout << "The smallest integer whose factorial is greater than 3000 is " <<
n << " and its factorial is "<< fact <<"."<<endl;
//end program
cin.get();
return(0);
}
int factorial(int n){
int i = 0;
int fact = 1;
{
for (i = 1; i <= n; i++){
fact = fact*i;
}
return(fact);
}
}