Small Factorials

I wrote this very simple code for the factorials like we are taught in math class but it is still wrong for codechef. Please help!

void fact(int x){
    int ans = 1;
    while(x!= 0){
        ans *= x;
        x--;
    }
    printf("%d\n", ans);
}

int main(void) {
	// your code goes here
	int n;
	scanf("%d" , &n);
	while(n--){
	    int x;
	    scanf("%d", &x);
	    fact(x);
	}
	return 0;
}

Factorials for small numbers also comes up to several digits. Please look up the forum for your doubt without posting straightaway.

2 Likes

Sorry I couldn’t find it as I am new to codechef and thanks.

Could you please explain to me how can I close this discussion?

I’m not sure of how to close a discussion :frowning_face: but i think it must be somewhere in the edit section of the original post.