fctrl2:codechef says" giving a wrong answer" while the program is perfectly fine..please help

#include <stdio.h>
#include <stdlib.h>

int main()


int i,j,t,n,f;








return 0;


Plz see the constraints carefully

hey @avrupa

About constraints:

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

So that mean your code should be able to calculate maximum of 100 factorial and factorial of 100 is


which cannot be stored in integer or floating point datatypes in c or c++, So you have to use array to store the number.

Now ho to do that ?

For this problem check this link: discuss.codechef.com/questions/7349/computing-factorials-of-a-huge-number-in-cc-a-tutorial

Hope you understood…! :slight_smile:

you cant store 100 factorial in any primitive data type in C and C++ .

Simplest way is to think about how you can create a program to multiply two numbers i.e. 22 x 44 = 968
and save the value in a character array.
x44 = multiply right ‘2’ of 22 with 44,calculate the 88%10 feed in array and in small classes there was a term called ‘carry’ while solving multiplication and that carry here is 88/10. (initially carry = 0 ). Then multiply left '2 with 44, add carry, calculate %10 and rest of the things as above
For more help refer to the editorials or comment here.

can u please let me know the changes in the program?

Well! The int data type can store a no. of 10^9 magnitude
And do you think 100! Can fit inside that :slight_smile:
Try thinking different :slight_smile:

thanx! that helped.

most welcome… :slight_smile: