Home > Back-end > 5!=1 * 2 * 3 * 4 * 5. Introducing a new concept of factorial, by each of the original number multipl
5!=1 * 2 * 3 * 4 * 5. Introducing a new concept of factorial, by each of the original number multipl
Time:06-09
For bosses to solve this problem is # include Int main (void) { Int I, a, n, j, m, d, sum; The scanf (" % d ", & amp; A); While (a -) { The scanf (" % d ", & amp; N); D=0; For (I=1; I & lt;=n; I++) { Sum=1; For (j=1; J & lt;=I; J++) { While (j % 2==0) The sum *=j; } D=d + sum; } printf("%d\n",d); } return 0; } this is me, don't know how to change the while where
CodePudding user response:
Starting from 2, don't need while
# include Int main (void) { Int I, a, n, j, m, d, sum; The scanf (" % d ", & amp; A); While (a -) { The scanf (" % d ", & amp; N); D=0; For (I=2; I & lt;=n; I++) { Sum=1; For (j=1; J & lt;=I; J++) { If (j % 2==0) The sum *=j; } D=d + sum; } Printf (" % d \ n ", d); } return 0; }
CodePudding user response:
For (j=2; J & lt;=I; J +=2) Why all traversal and then screen out half?