Posted on 2007-07-01 03:35
MiweiDev 阅读(404)
评论(0) 编辑 收藏 引用 所属分类:
C / C++Language
4.4 若a = 3,b = 4,c = 5, x = 1.2, y = 2.4, z = -3.6, u = 51274, n = 128765, c1 = 'a', c2 = 'b';
要求打印出如结果:
a=
3
b=
4
c=
5
x=
1.200000,y=
2.400000,z=
-3.600000
x+y=
3.60
y+z=-1.20
z+x=-2.40
u=
51274
n=
128765
c1='a'
or
97
c2='b'
or
98
注意对空格的控制:
1//方法一:直接对待本题
2#include <stdio.h>
3#define PI 3.1415
4
5void main()
6{
7 float r = 0.0;
8 float h = 0.0;
9 float l = 0, s = 0, s2 = 0,v = 0,v2 = 0;
10
11 printf("Please input r and h :\n");
12 scanf("%f %f",&r,&h);
13
14 l = 2 * PI * r;
15 s = PI * r * r;
16 s2 = s * 2 + l * h;
17 v = (4.0/3.0) * r * r * r * PI;
18 v2 = s * h;
19
20 printf("园的周长为:%f\n",l);
21 printf("园的面积为:%f\n",s);
22 printf("圆柱的面积为:%f\n",s2);
23 printf("园球体积为:%f\n",v);
24 printf("园柱的体积为:%f\n",v2);
25}
1//函数调用:
2#include <stdio.h>
3#define PI 3.1415
4
5void main()
6{
7 float GetL(float r);
8 float GetS(float r);
9 float GetS2(float r, float h);
10 float GetV(float r, float h);
11 float GetV2(float r, float h);
12
13 float r = 0.0;
14 float h = 0.0;
15 float l = 0, s = 0, s2 = 0,v = 0,v2 = 0;
16
17 printf("Please input r and h :\n");
18 scanf("%f %f",&r,&h);
19
20 l = GetL(r);
21 s = GetS(r);
22 s2 = GetS2(r,h);
23 v = GetV(r,h);
24 v2 = GetV2(r,h);
25
26 printf("园的周长为:%f\n",l);
27 printf("园的面积为:%f\n",s);
28 printf("圆柱的面积为:%f\n",s2);
29 printf("园球体积为:%f\n",v);
30 printf("园柱的体积为:%f\n",v2);
31}
32
33float GetL(float r)
34{
35 return (float)(2 * PI * r);
36
37}
38float GetS(float r)
39{
40 return (float)PI * r * r;
41}
42float GetS2(float r, float h)
43{
44 return (float)(GetS(r) * 2 + GetL(r) * h);
45}
46float GetV(float r, float h)
47{
48 return (float)((4.0/3.0) * r * r * r * PI);
49}
50float GetV2(float r, float h)
51{
52 return (float)(GetS(r) * h);
53}
4.9 输入一个华氏温度转换成设使温度:
已知:c = (5 / 9)(F - 32)
输出显示两个小数位:
1#include <stdio.h>
2void main()
3{
4 float F = 0.0;
5 float C = 0.0;
6
7 printf("请输入华氏温度:\n");
8 scanf("%f",&F);
9
10 C = (float)(5.0/9.0)*(F - 32);
11
12 printf("摄氏温度为:%.2f\n",C);
13}