C Program For NCR VALUE BY RECURSIVE FUNCTION
I have written a pascals triangle program. However, my program gets a
floating point exception somewhere between 60 and 70 and any subsequent
larger value. This is no doubt due to dividing two large numbers in
the nCr function. By using uint64_t instead of int helped get it this
far. I would like to see if it is possible to use it for larger
values. Unlike with most programs, execution time is of absolutely no
concern. Does anyone have any ideas? Here is my code:
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,ncr;
clrscr();
printf("Enter the n and r value:");
scanf("%d%d",&n,&r);
ncr=fact(n)/((fact(r))*(fact(n-r)));
printf("n=%d\n",fact(n));
printf("r=%d\n",fact(r));
printf("n-r=%d\n",fact(n-r));
printf("the ncr =%d\n",ncr);
getch();
}
int fact(int a)
{
int c=1,i;
for(i=1;i<=a;i++)
{
c=c*i;
}
return(c);
}

0 comments:
Post a Comment