I wrote the following code:
#include<stdio.h>
int main()
{
int t,a[5],i,fact=1,p;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=t;i++)
{
while(a[i]>=1)
{
fact=fact*a[i];
a[i]--;
}
printf("\n%d",fact);
fact=1;
}
return 0;
}
the website said “Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.”
while
this code has been accepted :
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int remi=0,mult,a[200]={0},i,j,m=1,n;
scanf("%d",&n);
a[1]=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
mult=a[j]*i;
mult+=remi;
a[j]=mult%10;
remi=mult/10;
}
if(remi>0)
{
while(remi)
{
a[++m]=remi%10;
remi/=10;
}
}
}
for(i=m;i>=1;i--)
{
printf("%d",a[i]);
}
printf("\n");
}
return 0;
}
I think , I have used less memory than this code.
Please help!!