Saturday, May 2, 2015

C Program find ncr


#include < stdio.h>

int fact(int );

void main()
{
    int n, r, ncr;
    clrscr();
    printf("\n Enter the value for N and R:");
    scanf("%d%d", &n, &r);
    ncr = fact(n) / (fact(r) * fact(n - r));
    printf("\n The value of ncr is: %d", ncr);
    getch();
}

int fact(int z)
{
    int f = 1, i;
    if (z == 0)
    {
return f;
    }
    else
    {
for (i = 2; i <= z; i++)
{
   f = f * i;
}
    }
    return f;
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner