#include <stdio.h>

int main(void) {

int T , n , i , f = 1 ;

scanf("%d" , &T);

while(T–){

scanf("%d" , &n);

for(i = 1 ; i <=n ; i++){

f *= i ;

}

printf("%d\n" , f);

f = 1 ;

}

return 0;

}

This code is to find the factorial of the number inputed. :"-(

21 gives a negative value

should i use recursion ? i tried using long for f but still yields a negative value … i am not getting it why its giving a negative value … can u pls tell me.

The range of long long int is 4*10^(19) (approximately) whereas 21! is 5*(10^19) approximately , hence it’s overflowing

1 Like

ouuuuhhhh … now i get it … so using double should solve the problem ?? thanx for telling

Naah , You will have to learn multiplication of very large no. , Just Google this thing

The output does give the desired answer after using double and the given range for the numbers is form 0 to 100 no more in the question , but it still keeps giving wrong answer when i try to submit … thanx for the help , i will look into multiplying very large numbers using c