compute

i'm having trouble trying to compute this S= n! = 1*2*3...*n
if someone could help me
And what is this "trouble" you're speaking of?
i have no idea how to do it
you should use a for loop and multiply the number with the prev number +1
like this:
1
2
3
4
5
6
int n=5;
int total=1;
for (int i=1;i<=n;i++) {
total=total*i;
}
cout<<total;
Last edited on
one more question what would i need to do if i want to ask the user if he he wants to retry would i need to create a new program?
put it in a while loop until his answer isno
Topic archived. No new replies allowed.