getting SIGSEGV for MARBLES question

i am not sure why i am getting this error.please help.my code is given below.

#include<stdio.h>
double find_ncr(unsigned long long n,unsigned long long  r)
{
   if(n<r)
   	return 0;
   else if(n==r)
   	return 1;
   else if(r==1)
   	return n;
   if(n==1)
   	return 1;
   return find_ncr(n-1,r)+find_ncr(n-1,r-1);
}

int main()
{
   unsigned long long n, r;
   unsigned long long t;
   scanf("%llu",&t);
   while(t--)
   {
   	   scanf("%llu%llu",&n,&r);
   	   if(r<=n/2)
 	   	printf("%.0lf\n",find_ncr(n-1,r-1));
 	   else
 	   printf("%.0lf\n",find_ncr(n-1,n-r));
   }
   return 0;
}

K,n can be as large as 10^9 so if you use recursion…program will eventually run out of memory resulting in Segmentation fault

2 Likes