fork download
  1. #include <stdio.h>
  2. /*
  3.  * 演習 1からnまでの総積(総乗)
  4.  */
  5. int main(void) {
  6. int i=1, n, pd=1; //総積pdを1で初期化
  7.  
  8. scanf("%d",&n);
  9. printf("%d",i);
  10. while(i<n){ //次の処理で1増えるため
  11. i = i + 1;
  12. pd = pd * i;
  13. printf(" x %d",i);
  14. }
  15. printf(" = %d\n",pd);
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5320KB
stdin
9
stdout
1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 = 362880