What is wrong in My Program? of factorial


#1

#include <stdio.h>

int fact();

int main(void) {

int tc;
scanf("%d",&tc);
int a[tc];
int res[tc];
int i = 0;
for(i = 0 ; i < tc ; i ++){
    
    scanf("%d",&a[i]);
    res[i] = fact(a[i]);
}

for(i = 0 ; i < tc ; i ++){
    
    printf("%d\n",res[i]);
}
return 0;

}

int fact(int n){

if(n == 1){
    return 1;
}else
    return n * fact(n - 1);

}


#2

insert parameter when initialized . change this int fact(); into this int fact(int n);


#3

Bro its still not working!!!
i think its IDE Problem


#4

post your output bro


#5

Input / Output
Output is correct but not accepted by Code Chef IDE
4
2
3
4
5
2
6
24
120


#6

share the link to the problem . i could help you


#7

The problem is that if the input exceeds 20 , then no primitive datatype can store the value and represent it , u can use python as it can handle large values or refer this tutorial by codechef : https://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/ to do it using primitive datatype in c.