资源预览内容
第1页 / 共80页
第2页 / 共80页
第3页 / 共80页
第4页 / 共80页
第5页 / 共80页
第6页 / 共80页
第7页 / 共80页
第8页 / 共80页
第9页 / 共80页
第10页 / 共80页
亲,该文档总共80页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
二 2.1 #include void main() /本题原考虑在 16 位机器上实验目前多为 32 位机器故已过时。 int a = 42486; cout oct a endl hex a endl; unsigned b = 42486; cout dec (signed)b endl; 2.2 #include #include const double pi = 3.1415926; void main() double radius1, radius2; cout radius1 radius2; cout setw(10) pi setw(10) radius1 setw(10) (pi*radius1*radius1) endl setw(10) pi setw(10) radius2 setw(10) (pi*radius2*radius2) endl; 2.3 #include #include const double e = 2.718281828; void main() cout setprecision(10) e endl setiosflags(ios:fixed) setprecision(8) e endl setiosflags(ios:scientific) e endl; 2.4 #include void main() cout How many students here?n 500n; 2.5 #include void main() cout size of char sizeof(char) byten size of unsigned char sizeof(unsigned char) byten size of signed char sizeof(signed char) byten size of int sizeof(int) byten size of unsigned sizeof(unsigned) byten size of signed sizeof(signed) byten size of short sizeof(short) byten size of unsigned short sizeof(unsigned short) byten size of long sizeof(long) byten size of signed long sizeof(signed long) byten size of unsigned long sizeof(unsigned long) byten size of float sizeof(float) byten size of double sizeof(double) byten size of long double sizeof(long double) byten; 2.6 1) please input 3 sides of one triangle: 6,6,8 a= 6.00,b= 6.00,c= 8.00 area of triangle is 17.88854 2) 该程序计算三角形的面积前后分为三部分输入处理输出。 3) /#include #include #include #include void main() float a,b,c,s,area; /printf(please input 3 sides of one triangle:n); cout a b c; /输入时以空格作为数据间隔 s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c); /printf(a=%7.2f,b=%7.2f,c=%7.2fn,a,b,c); cout setiosflags(ios:fixed) setprecision(2) a= setw(7) a ,b= setw(7) b ,c= setw(7) c endl; /printf(area of triangle is %10.5f,area); cout area of triangle is setw(10) setprecision(5) area endl; 4) #include #include #include float area(float a, float b, float c); /函数声明 void main() float a,b,c; cout a b c; /输入时以空格作为数据间隔 float result = area(a,b,c); /函数调用 cout setiosflags(ios:fixed) setprecision(2) a= setw(7) a ,b= setw(7) b ,c= setw(7) c endl; cout area of triangle is setw(10) setprecision(5) result endl; float area(float a, float b, float c) /函数定义 float s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c); 2.7In main(): Enter two numbers: 3 8 Calling add(): In add(),received 3 and 8 and return 11 Back in main(): c was set to 11 Exiting. 2.8 #include #include double Cylinder(double r, double h); void main() double radius, height; cout radius height; double volume = Cylinder(radius, height); cout 该圆柱体的体积为 volume endl; double Cylinder(double r, double h) return r*r*M_PI*h; 三 3.1 (1) sqrt(pow(sin(x),2.5) (2) (a*x+(a+x)/(4*a)/2 (3) pow(c,x*x)/sqrt(2*M_PI) /M_PI 为 BC 中 math.h 中的圆周率常数 3.2 13.7 2.5 9 3.3 (1) a1=1 a2=1 (2) 1.1 (3) 2,0.0 (4) 20 3.4 #include void main() int x; cout x; if(x=-1) cout (x-1) -1 & x=2) cout 2*x endl; if(2x & x=10) cout x*(x+2); 3.5 #include void main() int a; cout a; int c1 = a%3 =0; int c2 = a%5 =0; int c3 = a%7 =0; switch(c12)+(c21)+c3) case 0: cout 不能被 3,5,7 整除.n; break; case 1: cout 只能被 7 整除.n; break; case 2: cout 只能被 5 整除.n; break; case 3: cout 可以被 5,7 整除.n; break; case 4: cout 只能被 3 整除.n; break; case 5: cout 可以被 3,7 整除.n; break; case 6: cout 可以被 3,5 整除.n; break; case 7: cout
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号