29 December, 2012

C++ Program To Find NCR Factor.

This Post Contains A C++ Program To Find NCR Factor With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Functions' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.

# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Find NCR Factor.

/* Declaration Of Header Files */
# include < iostream.h >
# inlcude < conio.h >
int fact(int);  // Declaring fact() Function

/* Start Of Main Program */
void main()
{
       int n, c, r;
       clrscr();
       cout << " Enter Values For 'N' & 'R' :- ";
       cin >> n >> r;
       c = fact(n) / ( fact(r) * (fact( n - r ) ) );    // Calling fact() Function
       cout << endl << " NCR Factor Is :- " << c;
       getch();
}
/* End Of Main Program */

/* Defining fact() Function */
int fact( int x )
{
      int i, f = 1;
      for( i = x; i > 0; i-- )
      {
            f = f * i;
       }
       return(f);
}

Output :

Enter Values For 'N' & 'R' :-  6   4

NCR Factor Is :-  15





No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.