?? d4r3.cpp
字號(hào):
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
#include <stdlib.h>
#include <fstream.h>
#include <string>
double gammln(double xx)
{
int j;
float temp;
double cof[6],stp,half,one,fpf,x,tmp,ser;
cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;
stp = 2.50662827465;
half = 0.5;
one = 1.0;
fpf = 5.5;
x = xx - one;
tmp = x + fpf;
tmp = (x + half) * log(tmp) - tmp;
ser = one;
for (j = 1;j<=6;j++)
{
x = x + one;
ser = ser + cof[j] / x;
}
temp = tmp + log(stp * ser);
return temp;
}
double factln(int n)
{
int i;
double a[101],temp;
for( i = 1;i<=100;i++)
a[i] = -1.0;
if (n < 0)
{
cout<<"negative factorial";
exit(1);
}
if (n <= 99)
{
if( a[n + 1] < 0.0) a[n + 1] = gammln(n + 1.0);
temp = a[n + 1];
}
else
temp = gammln(n + 1.0);
return temp;
}
int bico(int n,int k)
{
int temp;
temp = int(exp(factln(n) - factln(k) - factln(n - k)));
return temp;
}
void main()
{
//program d4r3
//driver for routine bico
int i,nval,tt;
int n,k,binco;
char text[20];
fstream fin;
fin.open("d:\\vc常用數(shù)值算法集\\data\\fncval.dat",ios::in);
while (strcmp(text,"Binomial")!=0)
{
fin>>text;
}
cout<<"Binomial coefficients "<<endl;
fin>>text;
fin>>nval;
fin>>text;
cout<<endl;
cout<<" n k Actual bico(n,k)"<<endl;
for( i = 1;i<=nval;i++)
{
fin>>n;
fin>>k;
fin>>binco;
cout<<setw(6)<<n;
cout<<setw(8)<<k;
cout<<setw(12)<<binco;
tt=bico(n,k)+1;
cout<<setw(12)<<tt<<endl;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -