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

else cout<<\梯形法\ return 0; }

double jxf(int n) {

double sum=0;

for (int i=0;i<=n-1;i++) sum+=pi/n*f(i*pi/n); return sum; }

double txf(int n) {

double sum=0;

for (int i=0;i<=n-1;i++) sum+=pi/n*(f(i*pi/n)+f((i+1)*pi/n)); sum/=2; return sum; }

double f(double x) {

double y; y=sin(x)+cos(x); return y; }

4-6v2error

#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<<\矩形法\ else cout<<\梯形法\ return 0; }

double jxf(int n) {

double sum=0;

for (int i=0;i<=n-1;i++) sum+=pi/n*f(i*pi/n); return sum; }

double txf(int n) {

double sum=0;

for (int i=0;i<=n-1;i++) sum+=pi/n*(f(i*pi/n)+f((i+1)*pi/n)); sum/=2; return sum; }

double f(double x) {

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

#include using namespace std; int my(int x,int y); int mb(int x,int y);

int main() {

int a,b,max,min; cin>>a>>b; max=my(a,b);

min=mb(a,b);

cout<

int my(int x,int y) {

for (int i=(x>y?y:x);i>=1;i--)

if (x%i==0&&y%i==0) return i; }

int mb(int x,int y) {

for (int i=(x>y?x:y);i>=1;i++) if (i%x==0&&i%y==0) return i; } 4-11

#include using namespace std;

void delchar(char *s1,char s2); int main() {

char s1[100]; char s2; cin>>s1>>s2;