#include "iostream"
using namespace std;
int main()
{
char n[6],r[6];
int C(int,int);
while(true) {
cout<<"Input n(或直接按enter結束程式)$";
cin.getline(n,6);
if(n[0]=='\0') break;
cout<<"Input r(或直接按enter結束程式)$";
cin.getline(r,6);
if(r[0]=='\0') break;
int a=atoi(n),b=atoi(r);
cout<<"C("<<a<<","<<b<<")="<<C(a,b)<<endl;
}
return 0;
}
int C(int n,int r)
{
if(n<r) return 0;
else if(n==r && n>=0) return 1;
else if(r==0) return 1; //這行應該是必備條件 但不知題目為何沒給
else if(n>r && r>=1) return C(n-1,r)+C(n-1,r-1);
}
/*
Rule 1. C(n,r)=0 if n<r.
Rule 2. C(n,r)=1 if n=r≧0.
Rule 3. C(n,r)=C(n-1,r)+C(n-1,r-1) if n>r≧1.
*/
/*
Combination version 1.0.0-0
Copyright (C) 2002 Wu.Meng-Da (Avogau.cis94)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
--
明天不一定更美
但更美的明天一定會來
^^我們一起共勉之^^!☆★
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.122.192