1、main /* main function */ main后遗失了“()” float a,b,c,v; /*a,b,c are sides, v is volume of cube */ a=2.0; b=3.0; c=4.0 行尾遗失了“;v=a*b*c;, v) 行尾遗失了“; 第三章3.1 C 3.2 C 3.3 D 3.4 C 3.5 D 3.6 B 3.7 C 3.8 D 3.9 A 3.10 B 3.11 C 3.12 D 3.13 D 3.14 A 3.15 C 3.16 C 3.17 C 3.18 无答案 3.19 C 3.20 B 3.21 (1)-2002500(2)i=
2、-200,j=2500 (3)i=-200 j=2500 3.22 12 0 0 3.23 一条语句 ;3.24 ;3.25 100,25.81,1.89234 100 25.81 1.89234 100 25.81 1.89234 3.26 x=127,x= 127,x= 177,x= 7f,x= 127 3.27 x=127,x=127 ,x=$127 ,x=$000127,x=_d 3.28 a=513.789215,a= 513.79,a= 513.78921500,a= 513.78921500 三. 编程题和改错题3.29 修改后的程序如下:main() double a,b,c,
3、s,v;input a,b,c:);scanf(%lf%lf%lf,&a,&b,&c);s =a*b;a=%f,b=%f,c=%fn, a,b,c);s=%f,v=%fn,s,v);3.30 #include int a=560,b=60;560 minute is %d hour and %d minute.n,a/b,a%b);3.31 int a,b;a=1500;b=350;a div b is : %dn,a/b);a mod b is :,a%b);3.32 double a,b,c,ave;printf (input 3 double number : nscanf (%.1fn
4、,(a b c)/3);3.33 void main() int a,b,c,t;请依次输入整数a,b,c:%d%d%dn你输入的值是: a=%d,b=%d,c=%dn,a,b,c);t=b;b=a;a=c;c=t;交换之后的值是:a=%d,b=%d,c=%dn第四章4.1 A 4.2 A 4.3 A 4.4 D 4.5 C 4.6 A 4.7 B 4.8 C 4.9 D 4.10 C 4.11 非0 0 4.12 = =同级 = !=同级4.13 ! & | 4.15 !4.16 a = b | a 4 | x -4 4.17 1 4.18 x 0 4.19 3 2 2 4.20 *# 三.
5、 编程题4.21 略4.22 /* 检查日期的合法性 */ int checkdate(int year, int month, int day) if(year 2005) 输入的年份无效!nreturn 0;else if(month 12) 输入的月份无效!else if(day 31) 输入的日期无效!else switch(month) case 4:case 6:case 9:case 11:if(day 30) break;case 2:if(year%4 = 0 & year_0 != 0) | year0 = 0) 29) 28) 输入的出生日期无效!/* end of sw
6、itch(m0)*/ return 1;int y0, m0, d0; /* 生日 */ int y1, m1, d1; /* 当前日期 */ int years, months, days; /* 实足年龄*/ 请输入学生的生日:, &y0,&m0,&d0);if(checkdate(y0, m0, d0) 请输入当前日期:y1,&m1,&d1);/*当前日期合法性检查*/ if(!checkdate(y1, m1, d1) return;else if(y0 y1) 出生年份比当前年份晚!else if(y0 = y1) if(m0 m1) 出生年月比当前年月晚!else if(m0 =
7、m1) if(d0 d1) 出生年月日比当前年月日晚!/* 计算实足年龄 */ years = y1 - y0;months = m1 - m0;days = d1 - d0;/* 修正实足年龄天数*/ if(days 0) months-;switch(m1) case 1:case 5:case 7:case 10:case 12:days = 30;case 8:days = 31;case 3:if(y1%4 = 0 & y1_0 != 0) | y10 = 0) days = 29;days = 28;/* end of switch(m1) */ /* end of if(days
8、 0) */ /* 修正实足年龄月数*/ if(months months = 12;years-;/* end of if(months b)? a:b;max=(tempc)? temp:c;你输入的数中最大的是 %d.n,max);4.25 (1)不嵌套的if语句int x,y;input x :x);if ( x-5 & x0 ) y is %dn,y=x);if ( x=0 ) ,y=x-1);0 &10 ) ,y=x 1);=10 | x=-5) errorn(2)嵌套的if语句if(x -5) y is %d.nerror!if(0 = x) 10) (3)if_else语句if
9、( xelse if( x=0 ) else if( x(4)switch语句 switch (x) case -4:case -3:case -2:case -1:case 0:default:第五章5.1 D 5.2 C 5.3 B 5.4 C 5.5 C 5.6 B 5.7 D 5.8 A 5.9 D 5.10 D 5.11 5 4 6 5.12 死循环5.13 -1 5.14 11 5.15 d=1.0 k k=0 x 5.17 int i;int sig = 1;int sum = 0;for(i=1; i= 0.0004) i ;5.19 int year;int col = 0;
10、for(year=1600; year=2000; year ) %dt, year);col ;if(col%5 = 0) 5.20 #define N 7 int j;int m;int k = N/2;for(i=0; i m = i-k;if(m m *= -1;for(j=0; j j= 0 striLoop 9) num = 10*num (striLoop - %dn,num);6.22 int num = -1;do num ;while(strcmp(str, EOF);您输入了%d行字符!6.23 while(striLoop & iLoop N) az您输入了字符中有%d
11、个小写字母!6.24 int line;int iLoop1;int iLoop2;请输入图案的行数(不大于26):line);for(iLoop1 = 0; iLoop1 line; iLoop1 ) for(iLoop2 = 0; iLoop2 line - iLoop1; iLoop2 ) 2*iLoop1 1;%c,iLoop1 A第七章7.1 C 7.2 C 7.3 B 7.4 C 7.5 A 7.6 D 7.7 A 7.8 12 7.9 9.000000 7.10 4 7.11 n=1 s 7.12 =y z*x 7.13 1 s*i 0 f(k) 三. 程序调试和编程题7.14
12、fun(int n) int k,yes;for(k=2; k=n/2; k ) if(n%k = 0) yes = 0; break;else yes = 1;return yes;7.15 int mymod(int a, int b) return a%b;7.16 double fun(int n) double sum = 0;int iLoop;int sig = -1;for(iLoop=1; iLoop=n; iLoop ) sum = sig*1.0/iLoop;return sum;7.17 double t = 1.0;long tmp;for(iLoop=2;tmp = iLoop*iLoop;t -= 1.0/tmp;return t;7.18 double fun(double x) return x*x 5*x 4;int x = 2;y1=%fn, fun(x);y2=%fn, fun(x 15);y3=%fn, fun(sin(x);2005-7-29 17:53 myhome1702第八章8.1 A 8.2 B 8.3 B 8.4 C 8.5 B