FCTRL2 - Wrong answer

I get wrong answer even when the output is correct. I’ve used the sample input to verify my algorithm and it works, but it keeps rejecting my solution.

This is my code:

#include <stdio.h>

int factorial(int n);

int main() {

int t=0, i=0;

scanf("%d", &t);

int number [t];

for(i=0; i<t; i++){
    scanf( "%d",&number[i]);

    printf( "%d\n", factorial(number[i]));


return 0;


int factorial(int n){

if (n>=1){
    return n*factorial(n-1);
    return 1;


One good thing to do, before you ask some question is to maybe try and find an editorial or explore the comments section ( if there is such a thing ), and try to figure out if they have mentioned a solution. On the problem page, you can see the heading. They have written it in bold also, and provided link to a blog. Maybe you should read that.

Also, another suggestion to you is, avoid pasting your code in your post. Usually, people don’t like reading long posts. So, mostly people will ignore your post (unless you’re an editorialist xD ). But, seriously, no one likes to read code in a post. You should try to put your code online somewhere, and share the link. There are many such websites, and you can find anyone you like. Some examples are ideone and pastebin.

And finally, I have explained the same question here. So maybe, if you don’t find an editorial or blog etc, try to search on Discuss forums. Usually problem tag should give you many results, if there is ambiguity in question, or many people have doubt in it.

Sorry for the long post ( I know no one likes long posts ). Cheers!

This problem is not for beginners, as because the vale of ‘n’ is upto 100. It is not possible to to find the factorial of such large numbers in C/C++ without using Arrays. But, if you’re using Python/Java then it can be possible because of the BigInteger Libraries.

You can refer to this Tutorial: https://www.codechef.com/wiki/tutorial-small-factorials
My Submission in C++: https://www.codechef.com/viewsolution/22151091


Thank you so much. You’ve contributed with new knowledge for me, I wasn’t totally aware of the capabilities of C/C++. I’ll try another solution using arrays.

Thank you for your suggestions.