996 | CodeChef

#include
using namespace std;

int fact(int n){
int factorial=1;
for(int i=1;i<=n;i++){
factorial= factorial*i;
}
return factorial;
}
int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;

cout<<fact(n)<<endl;
}

return 0;

}

I’m getting correct output when I’m running the code, but why my answer
is not getting submitted? It says ‘Wrong Answer’

Brother your code is not wrong but the data types in c++ are not capable to hold large numbers.So you need to come up with a better solution. Here’s my code for reference:
https://www.codechef.com/viewsolution/41287543

Try With input
1 100
it will give you 0 which is not correct
100! =
933262154439441526816992388562667004-
907159682643816214685929638952175999-
932299156089414639761565182862536979-
208272237582511852109168640000000000-
00000000000000

100! has around 145-150 digits where long long can store only max 18 digits
So You need solve this question using array
You can search on youtube about factorial of large numbers you will get tutorial there
or you can get it on gfg also

thank you very much for the help. Actually I don’t know how to use that vector in programming yet, so it’s bit difficult to understand the code.