组合数求解公式m!/(n!(m-n)!)。编程序输入m,n,输入组合数,求要求用定义函数求现求阶乘。
#include <iostream>
using namespace std;
long fac ( int n )
{
int i , t = 1;
i = n;
for ( i; i > 0; i --)
{
t = t * n;
n = n - 1;
}
return t;
}
int main ()
{
int s, m, k ;
cout << "求算数m!/[n!(m-n)!],请输入m,k" << endl ;
cin >> m >> k;
s = fac( m ) / ( fac(k)*fac(m-k) );
cout << s << endl ;
return 0;
}
追加:查单词书
#include <iostream> #include "string" using namespace std ; int main () { char s1[100],s2[100]; int i=0,a,k=0,j,h=0; cout << " 输入字符串"<< endl; cin.get(s1,100); j = strlen(s1); for (a = 0; a <= j; a ++) { if('a'<=s1[a]<='z'||'A'<=s1[a]<='Z'||'0'<=s1[a]<='9') { if(s1[a+1]==' '||s1[a+1]==','||s1[a+1]=='.'||s1[a+1]=='?'||s1[a+1]=='!') { k=k+1; } } } cout<<k<<endl; system("pause"); return 0; }