Saturday, September 15, 2012

Code # 24:C Program To Find ncr and npr Using Function

| |

Basic C Language Program To Find ncr and npr Using Function  is explained below with a detailed explanation,you will find it easy to go through this program, Sample input and output screen shots has been provide for the better understandability to the user, leave a comment if you are satisfied with the code

#include<stdio.h>

long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);

main()
{
   int n, r;
   long ncr, npr;

   printf("Enter the value of n and r\n");
   scanf("%d%d",&n,&r);

   ncr = find_ncr(n, r);
   npr = find_npr(n, r);

   printf("%dC%d = %ld\n", n, r, ncr);
   printf("%dP%d = %ld\n", n, r, npr);

   return 0;
}

long find_ncr(int n, int r)
{
   long result;

   result = factorial(n)/(factorial(r)*factorial(n-r));

   return result;
}

long find_npr(int n, int r)
{
   long result;

   result = factorial(n)/factorial(n-r);

   return result;


long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
      result = result*c;

   return ( result );
}
Output:
Enter the value of n and r
8
4
8c4=70
8p4=1680

3 comments:

There are times when people are having lots of trouble while they are planning to download aol gold desktop in their computer. If you are also one of them, you need first to see whether your system is fulfilling all the requirement which is required for downloading the software.

AOL is one of the reliable email services that is used by many users. It comes with great features. However, while using the AOL web-based email service, many users confront various issues. These issues become the hurdle between the effective working of the AOL Customer service number uk email. A user can dial our AOL Customer support number and get in touch with us.

Post a Comment

Powered by Blogger.