C++ combination program problem

Score
0
Vote Up
February 16, 2012 at 20:32:22 Pacific
Specs: Windows 7

I would want to write a C++ program to show combination..but I cant do it.May anyone help me to check my program and teach me to correct it ??
My goal id to input the n and k then it will show the combination to me.

#include <iostream>
using namespace std;
int main()
{
int n,answer;
int j=1;
cout << "Input n and k :"<<endl;
cin >> n,k;
answer=(n - j + 1) / j ;
while(j<=k){
answer= answer *(n - j + 1) / j ;
++j ; }
cout<<"The number of combinations is :"<< answer << endl;
system("PAUSE");
return 0;
}


Reply ↓  Report •

Reply to Message Icon Start New Discussion
Related Posts

« batch file to find duplic... Java bits shifting within... »