fork download
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int t;
  5. int a[200]; //array will have the capacity to store 200 digits.
  6. int n,i,j,temp,m,x;
  7.  
  8. scanf("%d",&t);
  9. while(t--)
  10. {
  11. scanf("%d",&n);
  12. a[0]=1; //initializes array with only 1 digit, the digit 1.
  13. m=1; // initializes digit counter
  14.  
  15. temp = 0; //Initializes carry variable to 0.
  16. for(i=1;i<=n;i++)
  17. {
  18. for(j=0;j<m;j++)
  19. {
  20. x = a[j]*i+temp; //x contains the digit by digit product
  21. a[j]=x%10; //Contains the digit to store in position j
  22. temp = x/10; //Contains the carry value that will be stored on later indexes
  23. }
  24. while(temp>0) //while loop that will store the carry value on array.
  25. {
  26. a[m]=temp%10;
  27. temp = temp/10;
  28. m++; // increments digit counter
  29. }
  30. }
  31. for(i=m-1;i>=0;i--) //printing answer
  32. printf("%d",a[i]);
  33. printf("\n");
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 9432KB
stdin
45
stdout
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1