small factorial problem

I’m trying to submit my solution its running correctly with custom input but shows error while submitting it . so can anyone tell me why??

here is my code:

#include <iostream>
using namespace std;
int factorial(int num){
    if(num==0||num==1)
        return 1;
    return num*factorial(num-1);
}

int main() {
	int t,n;
	cin>>t;
	while(t--){
	    cin>>n;
	    int fact=factorial(n);
	   cout<<fact<<"\n";
	    
	}
	return 0;
}

Check out this discussion, it should help:

1 Like