C++与数据结构基础简明教程课后习题答案 下载本文

int fun3(int x,int y) {

int z=(x-y)*(x-y); return z; }

int fun4(int x,int y) {

int z=x*x-y*y; return z; } 4-4

#include using namespace std; double jc(int x); int sm(int x);

int main() {

int m,n,s2; double s1; cin>>m>>n;

s1=jc(m)/(jc(n)*jc(m-n)); s2=sm(m)-sm(n); cout<

}

double jc(int x) {

double s=1;

for (int i=1;i<=x;i++) s*=i; return s; }

int sm(int x) {

int s=0;

for (int i=1;i<=x;i++) s+=i; return s; } 4-6

#include #include using namespace std; double jxf(int n); double txf(int n); double f(double x); //const pi=3.1415927; int main() {

int n; double y1,y2;

cin>>n; y1=jxf(n); y2=txf(n);

cout<

double jxf(int n) {

double sum=0,s; for (int i=0;i<=n-1;i++) {

s=(i*3.14)/n; sum+=(3.14/n)*f(s); }

return sum; }

double txf(int n) {

double sum=0,s1,s2; for (int i=0;i<=n-1;i++) {

s1=i*3.14/n; s2=(i+1)*3.14/n;

sum+=3.14/n*(f(s1)+f(s2));

}

sum/=2.0; return sum; }

double f(double x) {

double y; y=sin(x)+cos(x); return y; } 4-6v1

#include #include using namespace std; double jxf(int n); double txf(int n); double f(double x); const pi=3.1415927; int main() {

int n; double y1,y2; cin>>n; y1=jxf(n); y2=txf(n);

if (abs(y1-2)>abs(y2-2)) cout<<\矩形法\