#include <bits/stdc++.h>
usingnamespace std;
int main()
{
int a[1000]; //array will have the capacity to store 200 digits.
int n,i,j,temp,m,x;
while(cin>>n)
{
a[0]=1; //initializes array with only 1 digit, the digit 1.
m=1; // initializes digit counter
temp = 0; //Initializes carry variable to 0.
for(i=1;i<=n;i++)
{
for(j=0;j<m;j++)
{
x = a[j]*i+temp; //x contains the digit by digit product
a[j]=x%10; //Contains the digit to store in position j
temp = x/10; //Contains the carry value that will be stored on later indexes
}
while(temp>0) //while loop that will store the carry value on array.
{
a[m]=temp%10;
temp = temp/10;
m++; // increments digit counter
}
}
int sum=0;
for(i=m-1; i>=0; i--) //printing answer
sum+=a[i];
printf("%d\n",sum);
}
return 0;
}
> int a[1000]; //array will have the capacity to store 200 digits.
I guess that an array of 1000 elements would hold 1000 digits. However, considering the input limits, ¿how many digits do you need?