Guys i am getting wrong answer but the output is right plz help

#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. :"-(

Try this input

1
21

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. :slight_smile:

The range of long long int is 410^(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 :slight_smile:

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 :slight_smile: