大学生C语言课后习题全部答案详解

合集下载

C语言程序设计课后各章节习题答案

C语言程序设计课后各章节习题答案
答include"math.h"
main()
{
float x,y,d;
printf("Input x,y:");
scanf("%f,%f",&x,&y);
d=sqrt((x-2)*(x-2)+(y-2)*(y-2));
if(d>1)printf(ntf("inside");
}
12有一函数
x-1 -5<x<0
y= x x=0
x+1 0<x<8
编写一程序,要求输入x的值,输出y的值。分别用不嵌套的if语句,嵌套的if语句,switch语句编写。
答使用不嵌套的if语句程序如下:
main()
{
int x,y;
printf("Input x:");
scanf("%d",&x);
答main()
{
int x,a,b,c;
printf("Input number:");
scanf("%d",&x);
a=x/100;/*变量a中记录x的百倍数字*/
b=x/10%10;/*变量b中记录x的十位数字*/
c=x%10;/*变量c中记录x的个位数字*/
if(a*a*a+b*b*b+c*c*c==x)
if(m==2)
d=28+f;
else
d=31-(m==4)+(m==6)+(m==9)+(m==11);
printf("%d-%d is %d days.\n",y,m,d);

c语言程序设计教程第二版课后习题答案

c语言程序设计教程第二版课后习题答案

c语言程序设计教程第二版课后习题答案【篇一:c语言程序设计教程_李含光_郑关胜_清华大学出版社习题答案习题答案[完美打印版]】1.单项选择题(1)a (2)c(3)d (4)c (5)b 2.填空题(1)函数(2)主函数(main)(3)printf() , scanf()第2章习题参考答案1.单项选择题1-5 cbccc 6-10 cdcdc 11-13 dbb 2.填空题(1)1(2)26 (3)6 , 4 , 2 (4)10 , 6(5)3.000000 (6)双精度(double)(7)9 (8)字母,数字,下划线(9)13.700000 (10)11(11)((m/10)%10)*100+(m/100)*10+m%10(12)0 (13)10 ,9 ,11(15)(x0y0)||(x0z0)||(y0||z0)(16)double (17)x==0(18)sqrt(fabs(a-b))/(3*(a+b))(19)sqrt((x*x+y*y)/(a+b))第3章习题参考答案1.单项选择题1-5 cccdd 6-10 bcdbc11-15 bcbbb16 a 2.填空题(1)用;表示结束(2){ }(3)y=x0?1:x==0?0:-1(4)y%4==0y%100!=0||y%400==0(5)上面未配对(6)default 标号(7)while , do while , for(8)do while(9)本次(10)本层 3.阅读程序,指出结果(1)yes(2)*(3)abother(4)28 70(5)2,0(6)8(7)36 (8)1(9)3,1,-1,3,1,-1(10)a=12 ,y=12(11)i=6,k=4 (12)1,-2 4.程序填空(1)x:y , u:z(2)m=n , m!=0,m=m/10(3)teps , t*n/(2*n+1) , printf(“%lf\n”,2*s) (4)m%5==0 ,printf(“%d\n”,k) (5)cx=getchar() , cx!=front , cx(6)double s=0, 1.0/k , %lf (7)s=0 , sgmin, 5.编程题(1). #include stdio.h int main() {double x,y; scanf(%lf,x); if(x1) y=x;else if(x=1.0x10) y=2*x-11; elsey=3*x-11;printf(%lf\n,y); return 0; } (2).#include stdio.h int main() {double x,y,z,min;scanf(%lf%lf%lf,x,y,z); if(xy) min=y; else min=x; if(minz)min=z;printf(min=%lf\n,min); return 0; } (3).#include stdio.h int main() {int y,m,d,flag,s=0,w,i;scanf(%d%d%d,y,m,d);flag=(y%4==0y%100!=0||y%400==0);w=((y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400)%7;for(i=1;i=m;i++) {switch(i) {case 1:s=d;break; case 2:s=31+d;break; case 3:s=59+d;break; case 4:s=90+d;break; case 5:s=120+d;break; case6:s=151+d;break; case 7:s=181+d;break; case8:s=212+d;break; case 9:s=243+d;break; case10:s=273+d;break; case 11:s=304+d;break; case12:s=334+d;break;} }s=(w+s)%7; if(s==0)printf(星期日\n); elseprintf(星期%d\n,s); return 0; }(4).#include stdio.h int main() {float p,r;scanf(%f,p); if(p=10) r=p*0.1;else if(p10p=20) r=10*0.1+(p-10)*0.075; else if(p20p=40)r=10*0.1+10*0.075+(p-20)*0.05; else if(p40p=60)r=10*0.1+10*0.075+20*0.05+(p-40)*0.03;else if(p60p=100)r=10*0.1+10*0.075+20*0.05+20*0.03+(p-60)*0.015; else if(p100)r=10*0.1+10*0.075+20*0.05+20*0.03+40*0.015+(p-100)*0.01; printf(%f\n,r); return 0; } (5).#include stdio.h int main() {char c;while((c=getchar())!=\n) {if(c=ac=z) c=c-32; putchar(c);}return 0; } (6).#includestdio.h int main() {int m,k=2;printf(输入一个正整数:\n); scanf(%d,m); while(km) if(m%k==0) {printf(%4d,k); m=m/k; } else k++;printf(%4d\n,m); return 0; } (7).#includestdio.h int main() {int a,n,s=0,p=0,i;scanf(%d %d,n,a); for(i=1;i=n;i++) {p=p*10+a; s=s+p; }printf(%d\n,s); return 0; } (8).#includestdio.h int main(){int i,j,k;for(i=1;i=9;i++) for(j=0;j=9;j++) for(k=0;k=9;k++)printf(%5d,100*i+10*j+k); return 0; }(9).#includestdio.h #includemath.h int main() {float a=-10,b=10,x,f1,f2,f; f1=(((2*a-4)*a+3)*a)-6; f2=(((2*b-4)*b+3)*b)-6; do {x=(a+b)/2;f=(((2*x-4)*x+3)*x)-6; if(f*f10) { b=x; f2=f; } else { a=x;f1=f; }}while(fabs(f)=1e-6); printf(%6.2f\n,x); return 0; }(10).#includestdio.h#includemath.h int main() {int n=2;double eps,t,s=0,x;scanf(%lf %lf,x,eps); t=x; s=t;while(fabs(t)=eps) {t=-t*(2*n-3)*x*x/(2*n-2); s=s+t/(2*n); n++; }printf(%d,%lf\n,n,s); return 0; }(11).#includestdio.h int main() {unsigned long s,t=0,p=1; scanf(%u,s); while(s!=0) {if((s%10)%2!=0) {t=t+(s%10)*p; p=p*10; }s=s/10; }printf(%u\n,t); return 0; }第4章习题参考答案1.单项选择题1-5 dddbd 6-10 badcd 11-14 bdab 2.填空题(1)2(2)嵌套,递归(3)全局变量,局部变量,静态变量,动态变量(4)auto , static , register , extern (5)外部变量(6)编译,运行 3.阅读程序,指出结果(1)15(2)5(3)5,4,3 (4)i=5 i=2 i=2 i=4 i=2(5)求水仙花数(6)-5*5*5(7)30 (8)0 10 1 11 2 124.程序填空(1)float fun(float , float) , x+y,x-y, z+y,z-y (2)x , x*x+1 (3)s=0 , a=a+b 5.编程题(1).while(s!=0) #includestdio.h { unsigned int fun(unsigned int);p=p+s%10; int main() s=s/10; { } unsigned int s; return p; scanf(%u,s); } printf(%u\n,fun(s)); (2). return 0;#includestdio.h } #includestdlib.h unsigned int fun(unsignedint s) #includemath.h { void f1(float,float,float,float); unsigned int p=0; void f2(float,float,float,float);【篇二:《c语言程序设计》课后习题答案(第四版)谭浩强】t>1.1什么是计算机程序11.2什么是计算机语言11.3c语言的发展及其特点31.4最简单的c语言程序51.4.1最简单的c语言程序举例61.4.2c语言程序的结构101.5运行c程序的步骤与方法121.6程序设计的任务141-5 #include stdio.hint main ( ){ printf (**************************\n\n);printf( very good!\n\n);printf (**************************\n);return 0;}1-6#include stdio.hint main(){int a,b,c,max;printf(please input a,b,c:\n);scanf(%d,%d,%d,a,b,c);max=a;if (maxb)max=b;if (maxc)max=c;printf(the largest number is %d\n,max);return 0;}第2章算法——程序的灵魂162.1什么是算法162.2简单的算法举例172.3算法的特性212.4怎样表示一个算法222.4.1用自然语言表示算法222.4.2用流程图表示算法222.4.3三种基本结构和改进的流程图262.4.4用n?s流程图表示算法282.4.5用伪代码表示算法312.4.6用计算机语言表示算法322.5结构化程序设计方法34习题36第章最简单的c程序设计——顺序程序设计37 3.1顺序程序设计举例373.2数据的表现形式及其运算393.2.1常量和变量393.2.2数据类型423.2.3整型数据443.2.4字符型数据473.2.5浮点型数据493.2.6怎样确定常量的类型513.2.7运算符和表达式523.3c语句573.3.1c语句的作用和分类573.3.2最基本的语句——赋值语句593.4数据的输入输出653.4.1输入输出举例653.4.2有关数据输入输出的概念673.4.3用printf函数输出数据683.4.4用scanf函数输入数据753.4.5字符数据的输入输出78习题823-1 #include stdio.h#include math.hint main(){float p,r,n;r=0.1;n=10;p=pow(1+r,n);printf(p=%f\n,p);return 0;}3-2-1#include stdio.h#include math.hint main(){float r5,r3,r2,r1,r0,p,p1,p2,p3,p4,p5;p=1000;r5=0.0585;r3=0.054;r2=0.0468;r1=0.0414;r0=0.0072;p1=p*((1+r5)*5);// 一次存5年期p2=p*(1+2*r2)*(1+3*r3); // 先存2年期,到期后将本息再存3年期 p3=p*(1+3*r3)*(1+2*r2); // 先存3年期,到期后将本息再存2年期p4=p*pow(1+r1,5); // 存1年期,到期后将本息存再存1年期,连续存5次 p5=p*pow(1+r0/4,4*5); // 存活期存款。

C语言教材课后习题答案

C语言教材课后习题答案

2.简述程序设计语言发展的过程
程序设计语言经过最初的机器代码到今天接近自然语言的表达, 经过了四代的演变。 一 般认为机器语言是第一代,符号语言即汇编语言为第二代,面向过程的高级语言为第三代, 面对象的编程语言为第四代。
3.简述高级程序设计语言中面向过程与面向对象的概念。
“面向过程”是一种以过程为中心的编程思想。首先分析出解决问题所需要的步骤,然 后用函数把这些步骤一步一步地实现, 使用的时候依次调用函数即可。 一般的面向过程是从 上往下步步求精,所以面向过程最重要的是模块化的思想方法。 “面向对象”是一种以事物为中心的编程思想。面向对象的方法主要是将事物对象化, 对象包括属性与行为。 面向过程与面向对象的区别:在面向过程的程序设计中,程序员把精力放在计算机具体 执行操作的过程上,编程关注的是如何使用函数去实现既定的功能;而在面向对象的程序设 计中,技术人员将注意力集中在对象上,把对象看做程序运行时的基本成分。编程关注的是如 何把相关的功能(包括函数和数据)有组织地捆绑到一个对象身上。
不能使变量 k 得到正确数值的原因是: scanf("%d", &k);中的格式控制类型与变量 k 的定义类型不匹配,应将%d 改为%f.
习题 4 答案
选择题 1. B 2. A 3. B 4. B 阅读程序,写结果 7. 12 8.13 9. *0**2* 10. if(s>=90) m=4; else if(s>=80) m=3; else if(s>=70) m=2; else if(s>=60) m=1; else m=0; 11.输入 4 个整数 a,b,c,d,编写程序,将它们按从大到小顺序输出。 #include<stdio.h> main() { int a,b,c,d,t; scanf("%d%d%d%d",&a,&b,&c,&d); if(a<b) {t=a;a=b;b=t;} if(a<c) {t=a;a=c;c=t;} if(a<d) {t=a;a=d;d=t;} if(b<c) {t=b;b=c;c=t;} if(b<d) {t=b;b=d;d=t;} if(c<d) {t=c;c=d;d=t;} printf("%4d%4d%4d%4d",a,b,c,d); } 12.据所输入的 3 条边长值,判断它们能否构成三角形,如能构成,再判断是等腰三角形、 直角三角形还是一般三角形? 源程序: 5. C 6. B

c语言《程序设计基础》课后习题参考答案与解析

c语言《程序设计基础》课后习题参考答案与解析

c语言《程序设计基础》课后习题参考答案与解析《程序设计基础》习题参考答案与部分解析第1章 C 语言概述一、填空a) C源程序的基本单位是函数。

b) 一个C程序中至少应包括一个 main函数。

c) 在C语言中,输出操作是有库函数 printf( )函数完成。

二、单选题1、A2、C3、B解析:第1题答案:A 。

因为一个C程序总是从main函数开始执行的,而不论main函数在程序中的位置。

且到main函数结束。

第2题答案:C 。

因为 main函数没有限制必须位于程序的最前面。

C程序书写自由,一行内可写几个语句。

在对一个C 程序进行编译的过程中,无法检查注释当中的拼写错误。

不过C语言本身并没有输入输出语句,输入输出是由函数完成的。

第3题答案:B。

因为一个C语言程序是由若干个函数组成的。

但至少包含一个main 函数,且main函数的位置不限。

三、编程题1、编写一个输出“Welcome to C!”信息的小程序。

解:程序如下#include “stdio.h”main( ){1printf(“Welcome to C!”) ;}2、已知三角形的三边长分别为3,4,5,试用海轮公式编程求其面积。

海伦公式为:S?= ,其中s= (a+b+s)/2 ;解:程序如下#include “math.h”#include “stdio.h”main( ){int a , b , c ; /* a ,b,c 3个整型变量表示三角形的3条边。

*/float s ,s1 ; /* s1作为面积变量,s 作为中间变量是都应该是实形*/a=3 ; b= 4; c=5 ;s= (a+b+c)/2.0 ;s1= sqrt(s*(s-a)*(s-b)*(s-c)); /* sqrt函数完成开平方根功能。

*/printf(“area=%f\n”,s1);}2第2章程序设计基础知识一、单选题1、C2、A3、C4、A5、C6、C7、D8、C9、D 10、A 11、D 12、A 13、C 14、C 15、B A 16、B 17 D解析:1. 答案:C。

《C语言程序设计教程》第三版课后习题参考答案

《C语言程序设计教程》第三版课后习题参考答案

《C语言程序设计教程》第三版课后习题参考答案C语言程序设计教程第三版课后习题参考答案第一章:C语言概述1.1 C语言的特点答案:C语言是一种通用的、面向过程的程序设计语言,具有高效、简洁、灵活等特点。

它提供了丰富的程序设计元素和功能,适用于各种不同的应用领域。

1.2 C语言程序的基本结构答案:C语言程序由预处理指令、函数声明、函数定义、变量声明和语句组成。

其中,预处理指令用来引入头文件或定义宏,函数声明用来声明函数的名称和参数,函数定义用来实现函数的功能,变量声明用来声明变量的类型和名称,语句用来表达具体的计算过程。

1.3 C语言的数据类型答案:C语言提供了多种数据类型,包括基本类型(整型、浮点型、字符型等)和派生类型(数组、指针、结构体等)。

每种数据类型在内存中占据一定的存储空间,并具有特定的取值范围和操作规则。

1.4 C语言的运算符和表达式答案:C语言支持各种运算符和表达式,例如算术运算符(+、-、*、/等)、关系运算符(>、<、==等)、逻辑运算符(&&、||、!等)等。

通过运算符和表达式可以进行各种数值计算和逻辑判断。

第二章:基本数据类型与运算2.1 整型数据类型答案:C语言提供了不同长度的整型数据类型,包括有符号整型(int、long等)和无符号整型(unsigned int、unsigned long等)。

整型数据类型可以表示整数值,并具有不同的取值范围。

2.2 浮点型数据类型答案:C语言提供了浮点型数据类型(float、double等),用来表示带小数部分的实数值。

浮点型数据可以表示较大或较小的数值,并具有一定的精度。

2.3 字符型数据类型答案:C语言提供了字符型数据类型(char),用来表示单个字符。

字符型数据可以用于表示各种字符(包括字母、数字、符号等)。

2.4 布尔型数据类型答案:C语言不直接支持布尔型数据类型,但可以使用整型数据类型来表示布尔值(0表示假、非零表示真)。

昆明理工大学C语言程序设计课后习题答案

昆明理工大学C语言程序设计课后习题答案

昆明理工大学C语言程序设计课后习题答案第1章认识C语言(一)、是非题1.程序是指挥计算机进行各种信息处理任务的一组指令序列。

A.对B.错2.机器语言与硬件平台相关,但汇编语言和硬件平台无关。

A.对B.错3.编译型高级语言明显优于解释型高级语言。

A.对B.错4.C语言把高级语言的基本结构和低级语言的实用性紧密结合起来,不仅适合编写应用软件,而且适于编写系统软件。

A.对B.错5.面向对象的程序设计方法明显优于面向过程的程序设计方法。

A.对B.错6.计算机算法要有一个明确的起点和确定的步骤序列。

A.对B.错7.main函数是C程序的入口,由计算机系统负责调用。

A.对B.错8.在C语言中,同一行上可以写一条或多条语句,但一条语句不能写在多行上。

A.对B.错9.在C语言中,扩展名为.h的文件称为头文件,常用于组织C标准函数库中的函数。

A.对B.错10.注释语句会增加编译结果的复杂性,因此要尽量减少注释语句的数量。

A.对B.错11.声明变量的含义是通知编译系统为变量分配合适大小的存储空间。

A.对B.错12.C语言不允许使用关键字作为变量的名称,但可以使用保留字为变量命名。

A.对B.错13.符号常量提高了程序的可读性,但降低了程序维护的方便性。

A.对B.错14.变量声明把一个具体的标识符名称和计算机内存中的一个特殊的位置联系起来,同时确定了该位置存储的信息类型。

A.对B.错15. C语言允许在同一条语句中定义多个相同类型的变量,其间用分号进行分隔。

A.对B.错16.在ISO/ANSI 1999规定中,允许将变量声明放在程序中的任何位置。

A.对B.错17.不同类型的数据在内存中所占存储单元的大小不同,内部存储方式不同,取值范围不同,甚至能够参与的运算种类也不相同。

A.对B.错18.有符号和无符号整数的区别仅在于对数据最高位的解释不同。

若最高位解释为数据位,则为signed类型;若最高位解释为符号位,则为unsigned类型。

《C语言程序设计》课后习题答案(第四版)

《C语言程序设计》课后习题答案(第四版)

第1章程序设计和C语言11.1什么是计算机程序11.2什么是计算机语言11.3C语言的发展及其特点31.4最简单的C语言程序51.4.1最简单的C语言程序举例61.4.2C语言程序的结构101.5运行C程序的步骤与方法121.6程序设计的任务141-5 #include <stdio.h>int main ( ){ printf ("**************************\n\n");printf(" Very Good!\n\n");printf ("**************************\n");return 0;}1-6#include <stdio.h>int main(){int a,b,c,max;printf("please input a,b,c:\n");scanf("%d,%d,%d",&a,&b,&c);max=a;if (max<b)max=b;if (max<c)max=c;printf("The largest number is %d\n",max); return 0;}第2章算法——程序的灵魂162.1什么是算法162.2简单的算法举例172.3算法的特性212.4怎样表示一个算法222.4.1用自然语言表示算法222.4.2用流程图表示算法222.4.3三种基本结构和改进的流程图262.4.4用N S流程图表示算法282.4.5用伪代码表示算法312.4.6用计算机语言表示算法322.5结构化程序设计方法34习题36第章最简单的C程序设计——顺序程序设计37 3.1顺序程序设计举例373.2数据的表现形式及其运算393.2.1常量和变量393.2.2数据类型423.2.3整型数据443.2.4字符型数据473.2.5浮点型数据493.2.6怎样确定常量的类型513.2.7运算符和表达式523.3C语句573.3.1C语句的作用和分类573.3.2最基本的语句——赋值语句593.4数据的输入输出653.4.1输入输出举例653.4.2有关数据输入输出的概念673.4.3用printf函数输出数据683.4.4用scanf函数输入数据753.4.5字符数据的输入输出78习题823-1 #include <stdio.h>#include <math.h>int main(){float p,r,n;r=0.1;n=10;p=pow(1+r,n);printf("p=%f\n",p);return 0;}3-2-1#include <stdio.h>#include <math.h>int main(){float r5,r3,r2,r1,r0,p,p1,p2,p3,p4,p5;p=1000;r5=0.0585;r3=0.054;r2=0.0468;r1=0.0414;r0=0.0072;p1=p*((1+r5)*5); // 一次存5年期p2=p*(1+2*r2)*(1+3*r3); // 先存2年期,到期后将本息再存3年期p3=p*(1+3*r3)*(1+2*r2); // 先存3年期,到期后将本息再存2年期p4=p*pow(1+r1,5); // 存1年期,到期后将本息存再存1年期,连续存5次p5=p*pow(1+r0/4,4*5); // 存活期存款。

C语言课程 课后练习 参考答案

C语言课程 课后练习 参考答案

实验6-1课后练习:1.选择题(1)B (2)C(3)A(4)D(5)C (6)C (7)D 2.阅读程序,写出运行结果3020103.阅读程序,写出运行结果20104. 阅读程序,写出运行结果1 2 35.阅读程序,写出运行结果7 8 96.阅读程序,写出运行结果97.阅读程序,写出运行结果#include <stdio.h>int digit(int n,int k);int main(){ int n,k;printf("Enter n,k: ");scanf("%d %d",&n,&k);printf("\nThe result is:%d\n",digit(n,k));return 0;}int digit(int n,int k){ int d;while(k>0){ d=n%10;n=n/10;k--;}return d;}8.程序填空#include <stdio.h>double max(double a,double b);int main(){ double x,y;prinf("please input two double numbers:"); scanf("%lf %lf"),&x,&y;printf("%.2f\n",max(x,y));return 0;}double max(double a,double b){return (a>b?a:b);}9.原版#include <stdio.h>int check(int n,int d);int main(){ int n,d;printf("Enter n,d: ");scanf("%d %d",&n,&d);if(check(n,d)==1)printf("The digit %d is in data %d",d,n); elseprintf("The digit %d is not in data %d",d,n); return 0;}int check(int n,int d){ int temp;while(n>0){ temp=n%10;if(temp==d)return 1;n=n/10;}return 0;}改进版#include <stdio.h>int check(int n,int d);int main(){ int n,d,position;printf("Enter n,d: ");scanf("%d %d",&n,&d);position=check(n,d);if(check(n,d)>0)printf("The digit %d is in data %d,position is %d",d,n,position);elseprintf("The digit %d is not in data %d",d,n);return 0;}int check(int n,int d){ int temp,position=1;while(n>0){ temp=n%10;if(temp==d)return position;position++;n=n/10;}return 0;}实验6-2课后练习1.选择题(1)B (2)C(3)B(4)B(5)C (6)B (7)D (8)D (9)C(10)B(11)A2.填空(1) 函数中声明有局部变量,若声明中带有static,则该局部变量采用静态存储方式,在编译时分配空间,若函数中未显式设定初始值,则系统将其自动初始化,函数被调用结束时,该空间不释放。

C语言课后习题参考答案

C语言课后习题参考答案

C语言课后习题参考答案第一章:基础知识问题1:C语言的发展历史及特点C语言是由贝尔实验室的肯·汤普逊和丹尼斯·里奇在20世纪70年代初开发的一种高级程序设计语言。

它以其简洁、高效和可移植性而闻名。

C语言被广泛应用于系统级编程、嵌入式系统和科学计算等领域,并成为其他编程语言的基础。

问题2:C语言的基本数据类型及其存储范围C语言的基本数据类型包括字符型(char)、整型(int)、浮点型(float)、双精度浮点型(double)和空类型(void)。

它们的存储范围如下:- char:-128 到 127 或 0 到 255- int:-32,768 到 32,767 或 0 到 65,535- float:3.4E-38 到 3.4E38- double:1.7E-308 到 1.7E308- void:无特定存储范围问题3:如何在C语言中输出语句?在C语言中,可以使用printf函数来输出语句。

它的基本语法为:```cprintf("要输出的内容");```问题4:定义变量的语法规则在C语言中,定义变量的语法规则如下:```c数据类型变量名;```例如,定义一个整型变量x:```cint x;```问题5:如何进行变量的赋值?变量的赋值可以使用赋值运算符(=)。

例如,将一个整型常量10赋值给变量x:```cx = 10;```第二章:控制结构问题1:if语句的语法结构if语句用于根据条件执行不同的代码块。

它的基本语法结构如下:```cif (条件) {// 条件为真时执行的代码}```问题2:switch语句的用法及语法结构switch语句用于根据不同的表达式值执行相应的代码块。

它的基本用法及语法结构如下:```cswitch (表达式) {case 值1:// 当表达式的值等于值1时执行的代码break;case 值2:// 当表达式的值等于值2时执行的代码break;default:// 当表达式的值与所有case都不匹配时执行的代码break;}```问题3:循环语句的分类及语法结构C语言中的循环语句包括for循环、while循环和do-while循环。

C语言程序设计课后习题参考答案

C语言程序设计课后习题参考答案

《C语言程序设计》课后习题参考答案(总23页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--高等院校计算机基础教育规划教材《C++程序设计》课后习题参考答案――武汉大学出版社习题1参考答案一、选择题1. A2. D二、填空题1. BASIC、FORTRAN、AL_GOL60和COBOL2. 83. 关键字4. 编辑、编译、链接和运行三、简答题1.答:(1)C语言具有结构化的控制语句。

C语言提供了结构化程序所必需的基本控制语句,实现了对逻辑流的有效控制。

(2)C语言具有丰富的数据结构类型。

C语言除提供整型、实型、字符型等基本数据类型外,还提供了用基本数据类型构造出的各种复杂的数据结构,如数组、结构、联合等。

C语言还提供了与地址密切相关的指针类型。

此外,用户还可以根据需要自定义数据类型。

(3)C语言具有丰富的运算符。

C语言提供了多达34种运算符,丰富的数据类型与丰富的运算符相结合,使C语言的表达力更具灵活性,同时也提高了执行效率。

(4)C语言简洁、紧凑,使用方便、灵活,程序书写自由,有9种控制语句。

(5)C语言既具有高级语言的功能,又具有低级语言的许多功能,通常被称为中级计算机语言。

它既是成功的系统描述语言,又是通用的程序设计语言。

(6)C语言与汇编语言相比,可移植性好。

(7)功能强大。

C语言具有低级语言的一些功能,所以,生成目标代码质量高,程序执行效率高。

现在许多系统软件都用C语言来描述,可以大大提高了编程效率。

2.答:运行一个C语言程序,一般需要经过如下几个步骤:①上机输入并编辑源程序;②编译源程序;③与库函数连接;④生成可执行目标程序;⑤运行目标程序。

3.答:(1)操作系统的设计与实现。

C语言是一种应用非常广泛的结构化高级程序设计语言,既适合编写应用软件,又适合编写系统软件。

(2)工业控制。

由于C语言具有简洁、灵活、代码效率高、能进行位操作等优点,C语言大量应用在单板机、单片机上,以及嵌入式领域等。

大学C语言课本课后习题相应答案及详细解答

大学C语言课本课后习题相应答案及详细解答

5-1#include"stdio.h" void main(){char c1,c2;printf("c1:");c1=getchar();if(c1>='a'&&c1<='z') c2=c1-32;else if(c1>='A'&&c1<='Z') c2=c1+32;else c2=c1;printf("=>%c\n",c2);}5-2#include"stdio.h"void main(){char c;printf("c:");c=getchar();if(c>='A'&&c<='Z')if(c=='A') printf("没有前面的字母!");else if(c=='Z') printf("没有后面的字母!!");else printf("前面的字母=%c,后面的字母=%c",c-1,c+1);printf("\n");} 5-3#include"stdio.h"void main(){int s;char g;printf("s:");scanf("%d",&s);if(s>=0&&s<=100){switch(s/10){case 9:case 10: g='A';break;case 8: g='B';break;case 7: g='C';break;case 6: g='D';break;default: g='E';}printf("g=%c\n",g);}else printf("成绩不在百分制范围内!\n"); }5-4#include"stdio.h"void main(){int y,m,d,dok;int yy,mm,dd;printf("y,m,d:");scanf("%d,%d,%d",&y,&m,&d);switch(m){case 1: case 3: case 5: case 7: case 8: case 10: case 12:if(d>0&&d<=31) dok=4;else dok=0;break;case 4: case 6: case 9: case 11:if(d>0&&d<=30) dok=3;else dok=0;break;case 2: if(y%4==0&&y%100!=0||y%400==0)if(d>0&&d<=29)dok=2;else dok=0;elseif(d>0&&d<=28)dok=1;else dok=0;break;default: dok=0;}if(dok==0) printf("月份或日期不对!\n");else{switch(dok){case 1: if(d==28){yy=y;dd=1;mm=m+1;}else{yy=y;dd=d+1;mm=m;}break;case2:if(d==29){yy=y;dd=1;mm=m+1;}else{yy=y;dd=d+1;mm=m;}break;case3:if(d==30){yy=y;dd=1;mm=m+1;}else{yy=y;dd=d+1;mm=m;}break;case 4:if(d==31)if(m==12){yy=y+1;dd=1;mm=1;}else{yy=y;dd=1;mm=m+1;}else{yy=y;dd=d+1;mm=m;}break;}printf("Tomorrow:%d年%d月%d日\n",yy,mm,dd);}}5-5#include"stdio.h"void main(){int a,b,c,t;printf("a,b,c:");scanf("%d,%d,%d",&a,&b,&c);if(a+b>c&&b+c>a&&a+c>b){if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}if(a==b&&b==c) printf("等边三角形.");else if(a==b||b==c||a==c) printf("等腰角形.");else if(c*c==a*a+b*b) printf("直角三角形.");else printf("任意三角形.");printf("\n");}else printf("不能构成三角形!\n");}6-1#include"stdio.h"void main(){int a,b,m,n,k;printf("m,n:");scanf("%d,%d",&m,&n);a=m;b=n;k=a%b;while(k){a=b;b=k;k=a%b;}printf("%d\n",(m*n/b));}6-2#include"stdio.h"void main(){int n;int i,j,s;printf("n=");scanf("%d",&n);for(i=1;i<=n;i++){s=0;for(j=1;j<i;j++)if(i%j==0) s=s+j;if(s==i) {printf("%d:",i);for(j=1;j<i;j++)if(i%j==0) printf("%d ",j);printf("\n");}}} 6-3#include"stdio.h"#include"math.h"void main(){double x,y,zd,zx,x1,x2;zd=zx=50;for(x=0;x<=2;x=x+0.2){y=2*pow(x,3)-3*pow(x,4)+6*pow(x,5)-4*x+50;if(y>zd){ zd=y;x1=x;}if(y<zx){ zx=y;x2=x;}}printf("x=%f,max=%f\n",x1,zd);printf("x=%f,min=%f\n",x2,zx);}6-4#include"stdio.h"void main(){double x,sum=0,a,b,c;int i;printf("x=");scanf("%lf",&x);a=x;b=1.0;c=1.0;for(i=1;i<=10;i++){sum=sum+a/(b*c);a=a*x*x;b=b+2;c=c*i;}printf("y(%.2lf)=%lf\n",x,sum);}7-1/*选择排序*/#include"stdio.h"void main(){int i,j,n,k,temp;int a[10];printf("n(<10):");scanf("%d",&n);printf("Original:");for(i=0;i<n;i++) scanf("%d",&a[i]);for(i=0;i<n-1;i++){ /*趟*/k=i;for(j=i+1;j<n;j++) /*比较次数*/if(a[j]<a[k]) k=j;/*<升序,>?*/if(k!=i){temp=a[i];a[i]=a[k];a[k]=temp;}}printf("Ordered:");for(i=0;i<n;i++) printf("%d ",a[i]);printf("\n");}7-2#include"stdio.h"void main(){int a[3][3];int i,j,s=1;printf("Input:\n");for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%d",&a[i][j]);if(i==j) s=s*a[i][j];}printf("s=%d\n",s);} 7-3/*杨辉三角*/#include"stdio.h"void main(){int x[7][7];int i,j;for(i=0;i<7;i++) {x[i][0]=1;x[i][i]=1;}for(i=2;i<7;i++)for(j=1;j<i;j++)x[i][j]=x[i-1][j]+x[i-1][j-1];for(i=0;i<7;i++){for(j=0;j<=i;j++)printf("%3d",x[i][j]);printf("\n");}}7-4#include<stdio.h>#include<string.h>void main(){char str[21];int i,j;printf("str:");gets(str);for(i=0,j=strlen(str)-1;i<=j;i++,j--)if(str[i]!=str[j]) break;if(i>j) printf("%s是回文\n",str);else printf("%s不是回文\n",str);}7-5/*输入一维数组的10个元素,并将最小值与第1个数交换,最大值与最后一个数交换,然后输出交换后的结果*/#include<stdio.h>void main(){int a[10],i,zx,zd;printf("Input:\n");zx=zd=0;for(i=0;i<10;i++){scanf("%d",&a[i]);if(a[i]<a[zx]) zx=i;if(a[i]>a[zd]) zd=i;}if(zx!=0){int t;t=a[0];a[0]=a[zx];a[zx]=t;}if(zd!=9){int t;t=a[9];a[9]=a[zd];a[zd]=t;}for(i=0;i<10;i++)printf("%d ",a[i]);printf("\n");} 8-2#include"stdio.h"double xexp(double x,int n){double c;if(n==0) c=1.0;else c=x*xexp(x,n-1);return c;}void main(){int n;double x;printf("x:");scanf("%lf",&x);printf("n:");scanf("%d",&n);printf("Result=%g\n",xexp(x,n));}8-3#include"stdio.h"int find(int x[],int n,int y){int i,pos=-1;for(i=0;i<n;i++)if(x[i]==y) pos=i;return pos;}void main(){int a[10]={11,1,13,15,18,7,19,27,3,8};int i,y,pos;for(i=0;i<10;i++) printf("%d ",a[i]);printf("\ny:");scanf("%d",&y);pos=find(a,10,y);if(pos==-1) printf("Not found!\n");else printf("Position=%d\n",pos);}8-1#include"stdio.h"#include"conio.h" //getch()#include"stdlib.h" //srand(),rand(),system("cls") #include"time.h" //time()void main(){void init(int a[][5],int m,int n);void input(int a[][5],int m,int n);void output(int a[][5],int m,int n);int min(int b[][5],int m,int n);int a[5][5],ch='0';while(1){system("cls"); //清屏printf("1.初始化 2.键盘输入0.结束程序:");printf("\n");if(ch=='0') break;else if(ch=='1'){init(a,5,5);output(a,5,5);}else if(ch=='2'){input(a,5,5);output(a,5,5);}else printf("Error!\n");printf("Min element:%d\n",min(a,5,5));printf("按任意键继续!\n");getch();}}void init(int a[][5],int m,int n){int i,j;srand(time(0)); //time(0)表示以当前的时间做种子,增加每次运行的随机性for(i=0;i<5;i++)for(j=0;j<5;j++)a[i][j]=rand()%100; //随机数范围:0~32767,将它控制在0~99的范围}void input(int a[][5],int m,int n){int i,j;printf("Input Array 5X5:\n");for(i=0;i<m;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);}void output(int a[][5],int m,int n){int i,j;printf("Output Array 5X5:\n");for(i=0;i<5;i++){for(j=0;j<5;j++)printf("%2d ",a[i][j]);printf("\n");}}int min(int b[][5],int m,int n){int i,j,zx;zx=b[0][0];for(i=0;i<m;i++)for(j=0;j<n;j++)if(i==j&&b[i][j]<zx) zx=b[i][j];return zx;}8-4#include"stdio.h"float pave,nave;void saver(float a[],int n){int i,z,f;float psum,nsum;psum=nsum=0.0;z=f=0;for(i=0;i<n;i++)if(a[i]<0) {nsum=nsum+a[i];z++;}else if(a[i]>0) {psum=psum+a[i];f++;}else continue;pave=(z!=0?psum/z:0.0);nave=(f!=0?nsum/f:0.0);}void main(){float a[10]={1.0,11.0,3.0,-1.5,-5.5,-2};saver(a,10);printf("pave=%.1f,nave=%.2f\n",pave,nave); } 8-5#include"stdio.h"#include"math.h"void p1(int a,int b){printf("has two equal roots:%\n",-b/(2*a));}void p2(int a,int b, int disc){float x1,x2;x1=(-b+sqrt(disc))/(2*a);x2=(-b-sqrt(disc))/(2*a);printf("Has distant real roots:% and %\n",x1,x2);}void p3(int a,int b, int disc){float real,image;real=-b/(2*a);image=sqrt(-disc)/(2*a);printf("Has complex roots:\n");printf("%+%8.4fi\n",real,image);printf("%-%8.4fi\n",real,image);}void main(){ int a,b,c,disc;printf("a,b,c:");scanf("%d,%d,%d",&a,&b,&c);disc=b*b-4*a*c;if(fabs(disc)<=1e-6) p1(a,b);else if(disc>1e-6) p2(a,b,disc);else p3(a,b,disc);}8-6#include"stdio.h"#include"stdlib.h"#include"conio.h"#include"time.h"void main(){void printaverage(int score[][5],int m,int n);void printname(int score[][5],int m,int n);int score[10][5];int i,j;srand(time(0));for(i=0;i<10;i++)for(j=0;j<5;j++)score[i][j]=50+rand()%50+1;printf("Output Students' score:\n");printf("Course 1 2 3 4 5\n");printf("-------------------------\n");for(i=0;i<10;i++){printf("No.%2d:",i+1);for(j=0;j<5;j++)printf("%3d ",score[i][j]);printf("\n");}printaverage(score,10,5);printname(score,10,5);} void printaverage(int score[][5],int m,int n){int i,j,sum;printf("\nAverage score:\n");for(i=0;i<m;i++){sum=0;for(j=0;j<n;j++)sum=sum+score[i][j];printf("No.%d:%.1f\n",i+1,sum/5.0);}}void printname(int score[][5],int m,int n){int i,j,max0,row0;for(j=0;j<5;j++){max0=score[0][j];for(i=0;i<10;i++)if(score[i][j]>max0){max0=score[i][j];row0=i;}printf("Course %d,max score=%d,student:No.%d\n",j+1,max0,row0+1);}}大学英语I词汇练习题Choose the best one to complete each sentence.1. She felt like ____C___ frustration, but she was determined not to lose her self-control.A. to cry out ofB. to cry forC. crying out ofD. crying for2. The method he used turned out to be ___A____ in improving the students' English.A. effectiveB. abilityC. responseD. explicit3. Measures had to be taken in face of the housing problem that ____C____ in the city.A. foundedB. raisedC. aroseD. produced4. Without electronic computers, much of today's advanced technology ___D____.A. haven't been achievedB. wouldn't be achievedC. hadn't been achievedD. wouldn't have been achieved5. Jane said to her husband, "Don't worry. There is no cause for __B______ about our daughter'sability to manage herself."A. careB. concernC. attentionD. love6. The tap won't ____A____, and there is water all over the floor.A. turn offB. turn downC. turn onD. turn up7. Wearing the right shoes and clothes ____B____ being fit can make all the difference.A. in additionB. as well asC. alsoD. too8. She didn't try to do anything for her daughter, and ____B____ it's too late now.A. in caseB. in any caseC. at this caseD. in case of9. The girl said she hated _____C___ he smiled at her.A. that wayB. this wayC. the wayD. all the way10. I'll call the hotel. I'll tell them we'll ____A____ tomorrow morning and stay there for two nights.A. check inB. check outC. check offD. check over11. My father didn't go to New York; the doctor suggested that he ___C____ there.A. not to goB. won'tC. not goD. not to go to12. She _____C____ him to find answers to her problems.A. learned fromB. came intoC. leaned onD. subjected to13. The large wings of that bird ______B_____ it to fly high and fast.A. makeB. enableC. forceD. realize14. If he ____D___ the policeman honestly, he would not have been arrested.A. would answerB. answerC. should answerD. had answered15. I intended ___A____ you last Sunday, but I had no time.A. to have called onB. calling onC. to be calling onD. to be called on16. If you try to learn too many things at a time, you may get ____D___.A. alarmedB. scaredC. surprisedD. confused17. I haven't read this book, and my brother hasn't ____A____.A. eitherB. neitherC. alsoD. too18. No sooner ____B_____ than the truck started off.A. his luggage was loadedB. had his luggage been loadedC. loaded his luggageD. his luggage was being loaded19. At the end of the game, the whole crowd ____C____ their feet and cheered wildly.A. emerged fromB. rose fromC. got toD. stood up20. Darren has decided to give ___D_____ football at the end of this season.A. inB. forC. offD. up21. Neither his friends nor his mother ____B____ his marriage to that girl.A. acceptB. acceptsC. agreeD. agrees22. Most people believe that he is quite _____A___ of lying to get out of trouble.A. capableB. enabledC. ableD. skilled23. We were told that most of our luggage would be _____B___ by sea.A. approachedB. transportedC. handledD. communicated24. The Broadcasting Museum also offers Saturday workshops to _____B___ children with the world of radio.A. contriveB. acquaintC. acquireD. admit25. Without a passport, leaving the country is ____D___.A. out of questionB. without questionC. in the questionD. out of the question26. She states her views very ___A______.A. definitelyB. definiteC. infiniteD. infinitely27. You need to ____D____ the employers that you can do the job.A. convictB. confuseC. confirmD. convince28.The little boy was so lucky to have ___B_____ the earthquake.A. surviveB. survived C .surviving D. survival29. It is ___B___ that later in life you will see each other again.A. likeB. likelyC. likedD. seemed30.Women’s social ____B____ has changed much over the years.A. stateB. statusC. statesD. statement31.The novel _____D____ the imagination of thousands of readers.A. caterB. cateredC. captureD. captured32.There are good chances of ______D______ working in this firm.A. prospectB. portionC. positionD. promotion33.If you are ______A_____ a night owl, having the first class start in the afternoon might be thebest thing that could ever happen to you.A. more ofB. more thanC. much moreD. more34. The conference discussed the fair ______A_____of income and wealth.A. distributionB. distributeC. contributionD. contribute35. I was so ___C__ in today's history lesson that I didn't understand anything.A. amazedB. confusingC. confusedD. amazing36. ___B___ in England, Anne Bradstreet both admired and imitated several English poets.A. Having born and educatedB. Born and educatedC. Since born and educatedD. To be born and educated37. You will see this product ___B___ wherever you go.A. to be advertisedB. advertisedC. advertiseD. advertising38. I never forget my __B__ with you for the first time.A. to meetB. meetingC. to have metD. having to be meeting39.She was so angry that she left like __B__ something at him.A. to throwB. throwingC. to have thrownD. having thrown40. We are ___C__ in different kinds of extracurricular activities on campus.A. having involvedB. to involveC. involvedD. involving41.Let me assure you that it was not done ______D_____.A. intensiveB. intensivelyC. intentionalD. intentionally42.This medicine can ____A____ the pain in no time.A. lessenB. lessC. looseD. loosen43.Advertising is often the most ____A____ method of product promotion.A. effectiveB. effectedC. emotionalD. efficient44.It is at 5 a.m. _C___ the train from Beijing to Guangzhou will arrive.A. forB. withC. thatD. when45.Things might have been much worse if the mother _B___ on her right to keep the baby.A. has been insistingB. had insistedC. would insistD. insisted46.Had he worked harder, he __B__ the exams.A. must have got throughB. would have got throughC. permitted are freshmenD. are permitted freshmen47.God knows, how can I ____A____ six exams a week?.A. endureB. tolerateC. bear D .suffer48.All their attempts ______C______ the child from the burning building were in vain.A. rescuedB. to have rescueC. to rescueD. in rescuing49,Could you find someone ______C_______ for me to play tennis with?A. to fitB. fitC. fittingD. suit50. The smooth space flight marks a big ______D______ for Chinese scientists.A. breakB. breakingC. breakupD. breakthrough51 Economic crises destroy the capitalist system, and they grow in size and ____A____.A. durationB. duringC. endureD. enduringpanies will have to do more than this if they are to ___B_____ the earthquake.A. survivedB. surviveC. survivesD. surviving53. The baby felt ____C____ by her parents.A. hateB. loveC. ignoredD. ignore54. There are good chances of ______D______ in this firm.A. moveB. motiveC. motionD. promotion55. She tried to ______D______ our friendship.A. underminedB. keptC. maintainedD. undermine56. The new airport will ______C___ tourism.A. helpedB. useC. facilitateD. benefited57. They were full of ____B____ when they saw my new car.A. jealousB. envyC. pitifulD. loves58. This medicine can ____A____ the pain in no time.A. lessenB. lessC. leastD. little59.He _______A_____ her on her last physics paper.A. complimentedB. complimentC. completeD. completed60. Mrs. Hill is _______B____ on Tom’s marrying Susan.A. awareB. keenC. kindD. keep61. Let me assure you that it was not done ______C_____.A. internationalB. purposeC. intentionallyD. intentional62.The novel _____D_____ the imagination of thousands of readers.A. seizeB. catchC. captureD. captured63. If you yell ___A____ someone, you should apologize.A. atB. outC. ofD. under64. He came over and ____B____ a piece of paper into my hand.A. shoveB. shovedC. shovesD. shoving65. The girl student whose father is a senior engineer used to ___A____ abroad.A. studyB. studyingC. studiesD. studied66.The doctor tried to help ____D____ the function of his limbs.A. storeB. storesC. restoresD. restore67. Women’s social ____B____ has changed much over the years.A. placeB. statusC. landD. work68. It was he ___A___ knew he didn’t need to be afraid to make mistakes at that moment.A. whoB. whomC. whichD. whose69. A dropped cigarette is being ____C____ for the fire.A. firedB. fireC. blamedD. blame70. Advertising is often the most _____D___ method of promotion.A. effectB. affectC. affectedD. effective71.In time you’ll _____A_____ the beauty of this language.A. appreciateB. appreciatesC. appreciatedD. appreciating72. ______B___ is his favorite toy is hard for the kid to decide.A. whoB. whichC. howD. where73. After dinner, I took a ____A____ around the park.A. strollB. divingC. runD. walking74. The boy really enjoyed the useful and ____B____ work in science.A. creationB. creativeC. createdD. creator75. Some professions are _____A_______ with people who have not grown up.A. stuffedB. stuffC. stiffD. stiffed76. Economic crises destroy the capitalist system, and they grow in size and ____A____.A. durationB. duringC. endureD. enduring77. The new airport will ____C_____ tourism.A. helpedB. useC. facilitateD. benifited78. Let me assure you that it was not done _____C______.A. internationalB. purposeC. intentionallyD. intentional79. The girl student whose father is a senior engineer used to ___A____ abroad.A. studyB. studyingC. studiesD. studied80. Advertising is often the most ____D____ method of promotion.A. effectB. affectC. affectedD. effective81. It was he ___A___ knew he didn’t need to be afraid to make mistakes at that moment.A. whoB. whomC. whichD. whosepanies will have to do more than this if they are to _____B___ the earthquake.A. survivedB. surviveC. survivesD. surviving83. The baby felt ____C____ by her parents.A. hateB. loveC. ignoredD. ignore84. If you yell ___A____ someone, you should apologize.A. atB. outC. ofD. under85. Mrs. Hill is ______B_____ on Tom’s marrying Susan.A. awareB. keenC. kindD. keep86. _____A____ college takes hard work!A. SurvivingB. SurviveC. SurvivesD. To surviving87. It is absolutely ____A___ for the human beings to do something to save the earth.A. necessaryB. necessarilyC. unnecessaryD. unnecessarily88. An employer is more ____D____ to choose the candidate with high grades.A. likeB. probablyC. possiblyD. likely89. I don’t like this young woman. She seems a social ___D____.A. flowerB. workerC. negotiatorD. butterfly90. How should this ___B____ girl see the coldness of the letter?A. blindB. innocentC. warmD. pretty91. Be careful not to ___B____ yourself in their local conflicts.A. attendB. involveC. take part inD. participate92. Home prices are holding ____C___ in most regions, and people live with steady income.A. flexibleB. fierceC. stableD. shortage93. He was ______C______ by a newspaper reporter at that time.A. being interviewB. interviewC. being interviewedD. to interview94. They were full of ____C____ when they saw my new car.A. enviousB. envilyC. envyD. envies95. ________C_________, it is a very stable pattern producing results through effort .A. ContraryB. ConverseC. On the contraryD. Diverse96. The teacher doesn’t permit _____B____ in classA. smokeB. smokingC. to smokeD. to have a smoke97. The man in the corner confessed to ___A____ a lie to the manager of the company.A. have toldB. be toldC. being toldD. having told98. I never forget __B____ you for the first time.A. to meetB. meetingC. to have metD. having to be meeting.99. _______A___ a man has, ___________ he wants.A. The more, the moreB. More, moreC. The more, moreD. More, the more100. I see no _____B____ of his success.A. possibleB. possibilityC. possibilitiesD. probable101. He could be ____B____ about everything else in the world, but not about Manet, his loving child.A. visualB. criticalC. favoriteD. essential102. Some see themselves as the provider of ideas, ____C____ others view their role as essentially managerial.A. whenB. thereforeC. whileD. otherwise103. The idea ____A____ to him so much that he took it without hesitation.A. appealedB. interestedC. drewD. attracted104. The teacher evaluated the performance of each of his students who ____B____ evaluated his performance.A. by turnB. in turnC. at turnD. on turn105. Disease _____A____ during the journey and many passengers had to be rushed to hospital for treatment.A. broke outB. broke downC. started offD. started out106. The products have been _____A_____ to strict tests before leaving the factory.A. subjectedB. adjustedC. objectedD. constricted107. Our television set is out of order. Could you come and _____C_____ it for us?A. see throughB. see outC. see toD. see over108. _____C_____ they have taken matters into their hands, the pace of events has quickened.A. As thatB. So thatC. Now thatD. For that109. Our neighbor said if we made more noise he would _____B____ us to the police.A. inform ofB. complain aboutC. report toD. care for110. People working in the government should not _____A______ business affairs that might affect their political decisions.A. engage inB. hope forC. choose betweenD. pick on111. It's not easy to ______B______ to the top in show business.A. make outB. make itC. make upD. make them112. Carter is in charge of the office while I'm ______C______.A. leavingB. on leavingC. on leaveD. on relief113. We must ____B____ our attention on the question of reducing our cost.A. payB. focusC. absorbD. promote 114. Snap judgments, if ___B_____, have usually been considered signs of immaturity or lack of common sense.A. taking seriouslyB. taken seriouslyC. take seriouslyD. to be taken seriously115. Being with his family for a few days, I gained one or two insights ____A____ the reason he behaves the way he does.A. intoB. ofC. onD. off116. ___D___ your age or knowledge of the language, you'll be 100% involved in your studies from the first lesson to the last.A. As a result ofB. In spiteC. Despite ofD. Regardless of117. He said he had caught a bad cold and told me to ____D____ him.A. stay atB. stay upC. stay inD. stay away from118. Good managing of a company ___A_____ great efforts.A. calls forB. calls outC. calls inD. calls at119. I've looked ___C_____ all my papers but I still can't find the contract.A. uponB. outC. throughD. in120. When I'm going out in the evening I use the bike if I can, ___B_____ the car.A. regardless ofB. more thanC. other thanD. rather than121. We can't speak ___A____ our teacher.A. too highly ofB. too high ofC. highly of tooD. to highly of122. No one in our class ____D___ in sports than he.A. are more interestedB. are much interestedC. is much interestedD. is more interested123. As a teacher you have to ____B____ your methods to suit the needs of slower children.A. enlargeB. adjustC. affectD. afford124. ________A___ the hotel before soldiers armed with pistols and clubs charged into the crowd.A. Scarcely had they leftB. Scarcely they had leftC. Scarcely they leftD. Scarcely left they125. In the film, the peaceful life of a monk _____D_____ the violent life of a murderer.A. is compared withB. is compared toC. is contrasted toD. is contrasted with126 I didn't realize the food problem was so _____B___ in this city; with winter coming, many people would starve to death without more help.A. essentialB. criticalC. explicitD. effective127. Female socialization places importance on getting along with others, _____B___ male socialization places importance on becoming independent.。

《C语言程序设计教程》习题参考答案

《C语言程序设计教程》习题参考答案

《C语言程序设计教程》习题参考答案《C语言程序设计教程》习题参考答案祝胜林主编华南理工大学出版社【习题1】 (1)【习题2】 (2)【习题3】 (3)【习题4】 (5)【习题5】 (8)【习题6】 (11)【习题7】 (14)【习题8】 (17)【习题9】 (17)【习题10】 (20)一、简答题(在课本中寻找答案,略)1.1C程序的基本结构包括哪些内容?1.2如何定义标识符?1.3输入格式、输出格式的组成包括哪些内容?1.4C语言函数分为哪两类?1.5计算表达式的值应该考虑哪些方面?1.6上机调试程序的步骤如何?二、判断并改错1.7C程序执行的入口是main()函数,所以main函数必须放在程序的开头。

错误:main函数可以放在程序的任何位置。

并不限定在程序的开头。

1.8定义一个函数包括数据说明部分和执行语句部分,两者可以交叉出现。

错误:不可以交叉出现,数据说明部分在执行语句部分的前面。

1.9编辑与编译不是一回事。

错误:不是一回事。

编辑完成源程序的输入和修改;编译是对源程序进行语法检查,如果无语法错误,则生成目标程序。

1.10scanf("%d,%d",&x,&y);的正确输入格式:3,4<回车>。

正确1.11注释内容太多会影响程序的执行效率。

错误:不会影响程序的执行效率。

因为在编译时,编译系统将注释内容删除或用空格代替,所以注释内容不会编译到目标程序中。

1.12所有的数学公式可以直接出现在源程序中。

错误:数学公式需要转换成C语言能够接受的公式才能出现在源程序中。

三、编程题1.13在屏幕上输出自己名字的拼音。

提示:中文名字叫?张三?,对应的拼音为?Zhang San?,输出用printf()函数。

1.14 输入圆的半径,求圆的周长,并将结果保留两位小数输出到屏幕上。

提示:定义圆的半径r,圆的周长:2*3.14*r,输出结果保留2位小数可以用%.2f1.15输入两个整数,输出其中最大者。

C语言课后习题答案

C语言课后习题答案

1.1选择题:⑴一个C程序的执行是(A)。

A)从main()函数开始,直到main()函数结束B)从第一个函数开始,直到最后一个函数结束C)从第一个语句开始,直到最后一个语句结束D)从main()函数开始,直到最后一个函数结束⑵计算机能直接执行的语言是(B)。

A)汇编语言B)机器语言C)高级语言D)A和B⑶一个C程序是由(C)。

A)一个主程序和若干子程序组成B)若干过程组成C)一个或多个函数组成D)若干子程序组成⑷下列说法正确的是(B )。

A)C程序书写格式限制严格,一行内必须写一个语句B)C程序书写比较自由,一个语句可以分行写在多行上C)C程序书写格式限制严格,要求一行内必须写一个语句,并要求行号D)C程序中一个语句不可以分写在多行上1.2填空题:⑴构成C语言程序的基本单位是函数。

⑵C语言源程序文件的后缀是.c,经过编译后,生成文件的后缀是,obj,经过连接后,生成文件的后缀是.exe。

⑶在TURBO C环境中用RUN命令运行一个C程序时,所运行的程序的后缀是.exe。

⑷一个C语言程序必须有而且只能有一个主函数,它的函数名为main。

⑸一个函数有两部分组成,第一部分称为函数首部;第二部分称为函数体。

⑹函数体由符号{开始,用符号}结束。

函数体的前面是声明部分,其后是执行部分。

1.3上机编辑、调试、运行下列程序,发现错误,并改正之。

/*求1 + 2 + 3 + ……+ 10的和*/#include <stdio.h>main(){int sum,n;sum = 0;n = 1;while(n < 10){sum = sum + n;n = n + 1;}printf("sum = %d \n",sum);}2.1选择题⑴ 在以下标识符中,( B )是合法的用户标识符。

A ) a#bB ) getchC ) voidD ) ab*⑵ 不合法的八进制数是( B )。

(word完整版)C语言程序设计课后习题1-8参考答案

(word完整版)C语言程序设计课后习题1-8参考答案

C语言程序设计课后习题1—8参考答案习题1参考答案一、简答题1、冯诺依曼计算机模型有哪几个基本组成部分?各部分的主要功能是什么?答:冯诺依曼计算机模型是由运算器、控制器、存储器、输入设备、输出设备五大功能部件组成的。

运算器又称算术逻辑部件,简称ALU,是计算机用来进行数据运算的部件。

数据运算包括算术运算和逻辑运算。

控制器是计算机的指挥系统,计算机就是在控制器的控制下有条不紊地协调工作的.存储器是计算机中具有记忆能力的部件,用来存放程序和数据.输入设备是用来输入程序和数据的部件。

输出设备正好与输入设备相反,是用来输出结果的部件。

2、简述计算机的工作原理。

答:计算机的工作原理可简单地概括为:各种各样的信息,通过输入设备,进入计算机的存储器,然后送到运算器,运算完毕把结果送到存储器存储,最后通过输出设备显示出来。

整个过程由控制器进行控制。

3、计算机软件系统分为哪几类?答:软件内容丰富,种类繁多,通常根据软件用途将其分为两大类:系统软件和应用软件。

系统软件是指管理、监控、维护计算机正常工作和供用户操作使用计算机的软件。

这类软件一般与具体应用无关,是在系统一级上提供的服务。

系统软件主要包括以下两类:一类是面向计算机本身的软件,如操作系统、诊断程序等。

另一类是面向用户的软件,如各种语言处理程序(像BC、VC等)、实用程序、字处理程序等。

在操作系统的基础上运行。

4、什么叫软件?说明软件与硬件之间的相互关系。

答:软件是指计算机程序及有关程序的技术文档资料。

两者中更为重要的是程序,它是计算机进行数据处理的指令集,也是计算机正常工作最重要的因素。

在不太严格的情况下,认为程序就是软件。

硬件与软件是相互依存的,软件依赖于硬件的物质条件,而硬件则需在软件支配下才能有效地工作.在现代,软件技术变得越来越重要,有了软件,用户面对的将不再是物理计算机,而是一台抽象的逻辑计算机,人们可以不必了解计算机本身,可以采用更加方便、更加有效地手段使用计算机。

大学生C语言课后习题全部答案详解

大学生C语言课后习题全部答案详解
}#include<stdio.h>
\
main()
{
int y,m,d,yt,mt,dt,age;
printf("请按格式2010-12-10输入你的生日");
scanf("%d-%d-%d",&y,&m,&d);
printf("请按格式2010-12-10输入今天的日期");
scanf("%d-%d-%d",&yt,&mt,&dt);printf(源自| 0——退出|\n");
printf("|------------------------|\n");
printf("请输入选项\n");
ch=getch();
putch(ch);
}
#include<stdio.h>
#include<conio.h>
main()
{
//定义
int a=0,b=0,he=0,cha=0,ji=0;
{printf("%4d",i);
n++;
}
}
printf("\n");
printf("%d",n);
}#include<stdio.h>
#include<math.h>
main()
{
int n=0,s=1,i=0;
printf("input:");
scanf("%d",&n);
for(i=1;i<=n;i++)

C语言程序设计教程 课后习题参考答案

C语言程序设计教程 课后习题参考答案
(2)编辑、编译、链接、执行
(3)一个C程序由一或多个函数组成,一函数若干条语句构成,每条语句的末尾必须以分号结束。
(4)标识符,关键字,运算符,分隔符,常量,注释符等
4.从键盘输入一个双精度小数,打印出它的余弦值。
#include <stdio.h>
#include <math.h>
main( )
else if( score>=90 )
printf(“优秀\n”);
else if( score>=80 )
printf(“良好\n”);
else if( score >= 70 )
printf(“中等\n”);
else if( score >= 60 )
printf(“及格\n”);
else
printf(“不及格\n”);
printf(“%lf\n”, result);
}
习题3
1.
(1)D(2)AD(3)C(4)B(5)A
(6)-(10):BDACB
2.
(1)3.141593,3.1416,3.142
(2)c=K
(3)| 123.46|,|123 |
(4)x= 1.23,y= 50.00
(5)0
3.
(1)scanf(%f”, c);改为:scanf(“%f”, &c);
{
double x;
scanf(“%lf”, &x);
printf(“%lf\n”, cos(x) );
}
第2章
1.
(1)BDE、ACFG
(2)D(3)C(4)C
2.
(1)错(2)错(3)错(4)对(5)错

C语言课后习题答案(最终)

C语言课后习题答案(最终)

C语言课后习题答案(最终)第0章习题1. 将下列十进制数分别转化为二进制数、八进制数和十六进制数:(1)128 (2)511 (3)1024 (4)65535 (5)1048575 答:(1)10000000、200、80 (2)111111111、777、1FF (3)10000000000、2000、400(4)1111111111111111、177777、FFFF (5)11111111111111111111、3777777、FFFFF2. 将下列二进制数转化为十进制数和十六进制数:(1)1100110101B (2)101101.1011B 答:(1)821、335 (2)45.6875、2D.B3. 写出下列数的原码、反码、补码:15、-20、-27/32 答:(1)00001111、00000000、00001111 (2)10010100、11101011、11101100 (3)1.1101100、1.0010011、1.00101004. 16位无符号定点整数的数值表示范围为多少?8位补码的表示范围是多少?16位补码的表示范围是多少?答:5.1968年Dijkstra提出结构化程序设计的思想的原因是什么?简要回答结构化程序设计的经典定义。

答:结构化程序设计概念的提出主要是源于程序结构的层次性与模块化使得构造出来的软件具有良好的可理解性和可维护性,随着软件规模的扩大与复杂性的提高,程序的可维护性成为程序设计者们关注的重要问题之一。

如果一个程序的代码块仅仅通过顺序、选择和循环这3种基本控制结构进行连接,并且每个代码块只有一个入口和一个出口,则称这个程序是结构化的。

6.C程序在内存中存储在哪儿?计算机的内存空间是如何分区的?分区存放不同类型的数据的目的是什么?答:0~65535、-128~127、-32768~32767C语言程序属于应用程序,程序代码本身存放在应用程序区,程序运行时处理的数据存计算机的内存空间主要分为3个区:系统程序区、应用程序区和数据区,其中数据区放在应用程序数据区。

C语言程序设计习题答案(第三版)

C语言程序设计习题答案(第三版)

C语言程序设计(第三版)习题答案习题一一、名词解释(1)程序P1 (2)程序设计P1 (3)机器语言P1 (4)高级语言P2(5)汇编程序P3 (6)编译程序P4 (7)算法P5 (8)结构化程序设计方法P10二、简答题1. 设计程序时应遵循哪些基本原则?P4答:正确性、可靠性、简明性、有效性、可维护性、可移植性。

2. 算法具有哪些特点?答:有穷性、确定性、有效性、有零个或多个输入、有一个或多个输出。

3. 算法的表示形式有哪几种?答:自然语言、伪代码、传统流程图、N-S流程图、计算机语言。

4. 结构化程序设计方法的三种基本结构是什么?答:顺序结构、选择结构和循环结构。

5. 传统流程图与N-S流程图最大的区别是什么?答:N-S流程图去掉了在传统流程图中常用的流程线,使得程序的结构显得更加清晰、简单。

三、用传统流程图或N-S流程图表示求解以下问题的算法。

1. 从键盘输入10个整数,求出其中的最小数并输出。

2. 求1+2+3+…+100的值。

3. 求10~50的所有素数之和。

4. 求下列分段函数的值。

四、请参照本章例题,编写一个简单的C 程序,输出以下三行信息。

**************************Yangtze University**************************#include <stdio.h>void main(){printf("**************************\n");printf(" Yangtze University\n");printf("**************************\n");}4X-1 (X ≤1) 5(X-1)+6 (1<X<5) 6-3X (X ≥5)习题二一、选择题1~10: B C D C D D B C A A11~20: D A C D B D B A C D二、填空题1.字母 L 或字母 l2. %c(或字符) 、 %d(或整数)3.在程序运行过程中,其值可以在一定的范围内变化的量4.'\0'5.小数形式、指数形式6.关键字、预定义标识符、用户标识符7.字母、数字、下划线、数字8. 189. 2 、 1 、 3010.双精度实数或double11.赋值、逗号、 20 、 20 、 20 、 412. 4 、 4习题三一、选择题1~10: B C C B C C C D C C注:第4题答案D为: 10 22↙33↙二、填空题1. printf 、 scanf2. h3."%5d"4.'\0'5. e 、 E6. 67. s 、 c8. *9. - 、 +10. i三、编程题1. 编写程序,从键盘输入一个以秒为单位的时间数,将其换算成几小时几分几秒,然后进行输出。

C语言程序设计教程(第2版)课后习题答案(完美版)

C语言程序设计教程(第2版)课后习题答案(完美版)

C语言程序设计教程(第二版)课后习题答案第一章C语言程序设计概述-习题答案1算法的描述有哪些基本方法?答1、自然语言2、专用工具2 C语言程序的基本结构是怎样的?举一个例子说明。

答1、C语言程序由函数构成;2、“/*”与“*/”之间的内容构成C语言程序的注释部分;3、用预处理命令#include、#define可以包含有关文件或预定义信息;4、大小写字母在C语言中是有区别的;5、除main()函数和标准库函数外,用户也可以自己编写函数,应用程序一般由多个函数组成,这些函数指定实际所需要做的工作。

3 C语言有什么特点?答1、具有结构语言的特点,程序之间很容易实现段的共享;2、主要结构成分为函数,函数可以在程序中被定义完成独立的任务,独立地编译代码,以实现程序的模块化;3、运算符丰富,包含的范围很广;4、数据类型丰富;5、允许直接访问物理地址,即可直接对硬件进行损伤,实现汇编语言的大部分功能;6、限制不太严格,程序设计自由度大,这样使C语言能够减少对程序员的束缚;7、生成的目标代码质量,程序执行效率高,同时C语言编写的程序的可移植性好。

4★指出合法与不合法的标识符命名。

答AB12--√leed_3-- a*b2--× 8stu--× D.K.Jon--× EF3_3--√ PAS--√ if--× XYZ43K2 --√ AVE#XY--× _762--√ #_DT5--× C.D--×5说明下列Turbo C热键的功能。

答F2:源文件存盘 F10:调用主菜单 F4:程序运行到光标所在行(用于调试程序) Ctrl+F9:编译并链接成可执行文件 Alt+F5:将窗口切换到 DOS 下,查看程序运行结果。

6说明下列Turbo C方式下输入并运行下列程序,记录下运行结果。

①main(){printf("********************\n");printf(" welcome you \n");printf(" very good \n);printf("********************\n");}②main()printf("please input three numbers;");scanf("%d,%d,%d",&a,&b,&c); /*教材S是错误的*/t=max(max(a,b),c);printf("max number is:%d\n",t);}int max(int x, int y){ int z;if(x>y)z=x;else z=y;return(z);}答运行结果:********************welcome youvery good********************运行结果:please input three numbers;3,1,4 /*左侧下划线内容为键盘输入*/max number is:47一个C程序是由若干个函数构成的,其中有且只能有一个___函数。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
s=s*2;
printf("2^%d=%d\n",n,s);
}#include<stdio.h>
#include<math.h>
main()
{
int n=0,sum=0,i=0;
printf("input:");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum=sum+pow(2,i);
}
}
}#include<stdio.h>
#include<math.h>
main()
{
int a,b,c;
double d,x1,x2;
scanf("%d%d%d",&a,&b,&c);
if(a==0)
printf("不合法的一元二次方程\n");
else
{
d=b*b-4*a*c;
if(d<0)
printf("没有实根\n");
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);
}
}
}#include<stdio.h>
\
main()
{
int y;
printf("请输入年份:");
scanf("%d",&y);
if(y>0)
{
if(y%400==0)
printf("%d年是闰年\n",y);
else
if(y%100==0)
printf("%d年是闰年\n",y);
else
if(y%4==0)
printf("%d年是闰年\n",y);
else
printf("%d年不是闰年\n",y);
}
else
printf("错误\n");
{
int i,n=0;
for(i=100;i<1000;i++)
{
if(i%10==2 || i%100==2)
{printf("%4d",i);
n++;
}
}
printf("\n");
printf("%d",n);
}#include<stdio.h>
main()
{
int i,n=0;
for(i=100;i<1000;i++)
age=yt-y;
if(mt<=m)
age--;
printf("你的年龄是:%d\n",age);
}#include<stdio.h>
main()
{
int a,b,c;
printf("输入三角形的三个边长");
scanf("%d%d%d",&a,&b,&c);
if((a+b>c) && (b+c>a) && (a+c>b))
printf("|------------------------|\n");
printf("请输入选项\n");
ch=getch();
putch(ch);
}
#include<stdio.h>
#include<conio.h>
main()
{
//定义
int a=0,b=0,he=0,cha=0,ji=0;
{
if(i%10==2 || i%100==2)
{printf("%4d",i);
n++;
}
}
printf("\n");
printf("%d",n);
}#include<stdio.h>
main()
{
int i,n=0;
for(i=100;i<1000;i++)
{
if(i%10==2 || i%100==2)
double shang,x;
//防止a,b的值为0
printf("请输入非零的a\n");
scanf("%d",&a);
printf("请输入非零的b\n");
scanf("%d",&b);
//运算
he=a+b;
cha=a-b;
ji=a*b;
shang=a/b;
x=(float)a/b;
//输出
printf("result:\n");
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);
}
}
}#include<stdio.h>
#include<math.h>
main()
{
int a,b,c;
double d,x1,x2;
scanf("%d%d%d",&a,&b,&c);
printf("2^1+2^2+....2^n=%d",sum);
}#include<stdio.h>
main()
{
char a='\0',b='\0';
int sum=0;
printf("请输入两个数字:");
a=getchar();
b=getchar();
sum=(a-'0')+(b-'0');
b=2;
if(100<=a&&a<1000)
b=3;
printf("输出%d\n",b);
}#include<stdio.h>
#include<math.h>
main()
{
float a,b,c,delta;
double x1,x2;
printf("请输入a,b,c:\n");
scanf("%f%f%f",&a,&b,&c);
if(a==0)
printf("不合法的一元二次方程\n");
else
{
d=b*b-4*a*c;
if(d<0)
printf("没有实根\n");
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);
double d,x1,x2;
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
printf("没有实根\n");
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);
delta=b*b-4*a*c;
if(delta<0)
printf("方程无实数解!\n");
else
{
x1=(-b+sqrt(delta))/2*a;
x2=(-b-sqrt(delta))/2*a;
printf("x1=%f,x2=%f\n",x1,x2);
}
}#include<stdio.h>
main()
}
}#include<stdio.h>
#include<math.h>
main()
{
int a,b,c;
double d,x1,x2;
scanf("%d%d%d",&a,&b,&c);
if(a==0)
printf("不合法的一元二次方程\n");
else
{
d=b*b-4*a*c;
if(d<0)
printf("没有实根\n");
{printf("%4d",i);
n++;
}
}
printf("\n");
printf("%d",n);
}#include<stdio.h>
#include<math.h>
main()
{
int n=0,s=1,i=0;
printf("input:");
相关文档
最新文档