My issue
why my code giving runtime error though my answers are correct in the run
My code
#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else if (n > 0) {
int product = 1;
for (int i = 1; i <= n; i++) {
product*= i;
}
return product;
}
}
int main() {
int ncr,T,L,R;
cin>>T;
for(int i=0;i<T;i++){
cin>>L>>R;
ncr= (factorial(R)/(factorial(L)*factorial(R-L)));
cout<<ncr<<endl;}
}
Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone