Monday, January 20, 2014

C++ Program to Calculate NCR Value Using Function

with 0 Comment
#include<iostream.h>
#include<conio.h>
int fact(int);
void main()
{
int n,r,i,ncr;
clrscr();
cout<<"\n NCR Value Using Factorial Function";
cout<<"\n *********************");
cout<<"\n INPUT";
cout<<"\n ****");
cout<<"\n Enter the n value:";
cin>>n;
cout<<"\n Enter the r value:";
cin>>r;
ncr=fact(n)/(fact(n-r)*fact(r));
cout<<"\n OUTPUT";
cout<<"\n ******";
cout<<"\n NCR Value is:"<<ncr;
getch();
}
int fact(int n)
{
int f=1,i;
for(i=1;i<=n;i++)
{
f=f*i;
}
return(f);
}

-------------------------------------------------------------------------------------

OUTPUT:
********
INPUT
-------
Enter the n value:6
Enter the r value :3

OUTPUT
----------
NCR Value is:20


Calculate NCR Value
----------------------
INPUT
-------
Enter the n value:7
Enter the r value :3

OUTPUT
----------
NCR Value is:35

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive