### Can you help do this while loop code? PLEASE! :)

Hi Everyone! Can you help me do this program because i am a beginner. =)
Here is the sample output:

Enter Number: 5
Solution:
5 x 4 x 3 x 2 x 1
Result is 120

Using WHILE LOOP CODE!!

TY IN ADVANCE TO THOSE WHO WILL HELP ME! :)

#include <stdio.h>

int main()
{
int n;
while(scanf("%d", &n) == 1)
{
int r = 1;
while(n > 0)
r *= (n--);

printf("%d\n", r);
}
return 0;
}
http://www.cplusplus.com/forum/beginner/109575/

Please don't double post. It is also appropriate to include your attempt at solving obvious homework problems. You won't learn by copying someone elses work. ;-)
I would just read in the input number, which it appears there should only be one, and then increment it.

Then I would create a while loop like:
 ``1234`` ``````while(num-- > 2){ .. .. }``````

Inside the loop, I would do the multiplication, and after the loop I would print the result.
@ ciphermagi: Too late, he's already been given the full solution in his duplicate thread.
 ``12345678910111213141516`` ``````#include int main() { using namespace std; int a; a = 5; int b; b = a; while(a > 1){ b *= (a-1); a-=1; } cout << b << endl; }``````

My output was 120. Hope this helps
Last edited on
i agree with @cnoeval. cant you give it 10 minutes to make one. believe me it is that easy
Last edited on
Topic archived. No new replies allowed.