大学C语言实用教程课后编程答案
《C语言程序设计实践教程》答案-完整版

4.2练习题一、选择题1.D2.B3.A4.B和D5.C6.A7.B二、填空题1.//或/* */2.主或main3.函数首部和函数体4.编译和连接5.公号5.2练习题一、选择题1.A2.D3.B4.B5.C6.C7.D8.A9.B10.B11.D12.B13.A或B14.C15.B17.D18.D19.C20.D21.B22.A23.D24.C25.C26.B27.C28.D29.A30.B二、填空题1.102,102.#define 宏名字符串3.14.n=15.-46.a=1,b= ,c=27.c=A8.n1=%d\nn2=%d9.a+b>c&&a+c>b&&b+c>a10.ch>=’a’&&ch<=’z’|| ch>=’A’&&ch<=’Z’11.712.013.1111000014.8,46.2练习题一、选择题1.A2.C3.D4.C5.A7.A8.D9.B10.C11.A12.A13.C14.B15.正确答案为:12345678二、填空题1.102.y=1 x%i==03.屏幕中间输出一个由星号组成的菱形4.15.136.(cx=getchar())!=-1 front=cx; 7.m%n8.49.*p px=&x py=&y三、读程序,写结果1.-12.3,1,-1,3.a=16,y=604.x=12,y=45.597.2练习题一、选择题1.B2.C3.C4.A5.D6.C8.D9.C10.D11.D12.D13.A14.B15.C16.B17.B18.A19.A20.D21.B22.D23.C24.D25.D26.C二、填空题1.‘a’02.a[k] a[k] a[k]3.0 64.A B C D EA5.1,66.k=p;7.i<j8.189.4,some string * test 10.you&me三、读程序,写结果1.5 4 8 2 02.10 24 15 6 3.love china! H w l 4.66 66 555.Front一、选择题1. A2. A3. B4. B5. B6. A7. D8. C9. A10. A11. A12. B13. B14. A15. B16. B17. C二、填空题1.122.Itis3.fun(n-1)*n fun(k)4.s[i]-t[i]5.n%m i-1 x[d]6.x=n x%10 x7.m=f(a,4)+f(b,4)-f(a+b,3)8.a=1,b=1三、读程序,写结果1.s=72.s=373.bij12一、选择题1. B2. C3. B4. D5. B6. A7. B8. D9. D10. B11. D12. A13. B14. C15. C16. C17. A18. D19. B20. D二、填空题1.b->day (*b).day2.DDBBCC3.zhang 170.000000wang 150.0000004.995.max=i min=i stud[max].name,stud[max].score stud[min].name,stud[min].score6.&r 1 feof(fp) break7.BBB AAA 1238.rewind三、读程序,写结果1.2002,shangxian2.32。
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语言程序设计教程》(第三版)课后习题参考答案(精选5篇)[修改版]
![《C语言程序设计教程》(第三版)课后习题参考答案(精选5篇)[修改版]](https://img.taocdn.com/s3/m/893b22c5a32d7375a517800b.png)
第一篇:《C语言程序设计教程》(第三版)课后习题参考答案C语言程序设计课后习题参考答案习题一一、单项选择题1、C2、B3、B4、C5、D6、A7、C8、A二、填空题1、判断条件2、面向过程编程3、结构化4、程序5、面向对象方法6、基本功能操作、控制结构7、有穷性8、直到型循环结构9、算法10、可读性11、模块化12、对问题的分解和模块的划分习题二一、单项选择题1、B2、D3、C4、B5、A二、填空题1、主2、C编译系统3、结构化4、程序5、面向对象方法6、.OBJ7、库函数8、直到型循环结构习题三一、单项选择题1、D2、B3、A4、C9、B10、C11、A12、D13、C17、B18、C19、C20、D21、A25、D26、A二、填空题1、补码2、10^-138~10^1 38、15~166、A7、B6、D7、B14、B15、C22、D8、C8、D16、A24、D、A3、实4、单目运算符、自右向左5、函数调用6、65,89习题四一、单项选择题1、D2、C3、D4、A5、D6、B7、A8、C9、B10、B二、填空题1、两, ;2、5.1690003、-200 2500、i=-200,j=2500回车、i=-200回车j=2500回车4、a=98,b=765.000000,c=4321.0000005、100 25.81 1.89234、100,25.81,1.89234、100回车25.81回车1.89234回车6、0,0,37、38、scanf(“%lf %lf %lf”,&a,&b,&c);9、13 13.000000 13.00000010、c=b-a;a=b+c;习题五一、单项选择题1、B2、D3、C4、B5、B6、D7、A8、B二、填空题1、1 、02、k!=03、if(x>4||xelse printf(“error!”); 4、if(((x>=1&&x=200&&x Printf(“%d”,x);5、16、17、10! Right!8、a=09、2,110、0习题六一、单项选择题9、D1、B2、C3、C4、B5、C6、B7、C8、A二、填空题1、无穷次2、83、205、3.66、*#*#*#$7、828、d=1.0 、k++、k9、!(x习题七一、单项选择题1、B2、D3、C4、C5、A二、填空题1、1 2 4 8 16 32 64 128 256 5122、a[age]++、i=18;i3、break、i==84、a[i]>b[i]、i3、j5、b[j]=0、b[j]=a[j][k]习题八一、单项选择题1、B3、C4、A5、A9、D10、B11、A12、C13、A二、填空题1、return1、return n+sum(n-1)2、return1、n*facto(n-1)习题九一、单项选择题1、D2、C3、D4、A5、C9、B10、C11、A13、B17、C18、A19、B20、C二、填空题1、int 、return z2、*p++3、’\0’、++4、p、max*q6、A7、D6、A7、C14、C15、B6、C7、C14、A15、D8、A8、D8、C习题十一、单项选择题1、D2、D3、A4、5、B6、A7、C8、B9、D10、11、C12、D13、D14、C二、填空题1、34 122、ARRAY a[10],b[10],c[10];3、2 34、ab、cd5、(*b).day、b->day6、adghi mnohi no7、(struct node *)、!=’\n’、p=top;8、p1=p1->next9、(struct list *)、(struct list *)、return (n)习题十一一、单项选择题1、A2、A3、B4、A5、B9、A10、B11、B12、B13、C17、D二、填空题1、ASCII(文本)、二进制2、pf=fopen(“A:\zk04\data xfile.dat”,”w”);3、fputc()、fputs()、fscanf()、fread()4、(后两个空)文件结束符、非0值7、B14、C15、D8、A16、A第二篇:C语言程序设计教程课后习题参考答案《C语言程序设计教程》课后习题参考答案习题1 1. (1)编译、链接.exe (2)函数主函数(或main函数)(3)编辑编译链接2.(1)-(5):DDBBC (6)-(10):ABBBC 3.(1)答:C语言简洁、紧凑,使用方便、灵活;C语言是高级语言,同时具备了低级语言的特征;C 语言是结构化程序设计语言,具有结构化的程序控制语句;C语言有各种各样的数据类型;C语言可移植性好;生成目标代码质量高,程序执行效率高。
课后题答案-C语言程序设计(第2版)

《C语言程序设计能力教程(第二版)》课后作业及实训题参考答案第1章进入C语言程序世界二、1. I love China!printf("we are students.\n")2. 6项目实训题参考答案1.编写一个C程序,输出以下信息:* * * * * * * * * * * * * * * * * * * *I am a student!* * * * * * * * * * * * * * * * * * * *main(){ printf("********************\n");printf(" I am a student!\n ");printf("********************\n");}2.已知立方体的长、宽、高分别是10cm、20cm、15cm,编写程序,求立方体体积。
解:main(){int a,b,c,v;a=10;b=20;c=15;v=a*b*c;printf("v=%d",v);}本程序运行结果为:v=3000第2章编制C程序的基础知识一选择题C B A B A C C二操作题,2,-8,23.000000,2.500000,-8.0000002. ABC DEFGHwhy is 21+35 equal 523.3 14 32 31 24. aa bb cc abcA N项目实训题1.定义一个符号常量M为5和一个变量n值为2,把它们的乘积输出。
#define M 5main(){ int n,c;n=2; c=M*n;printf("%d\n",c); }2.编程求下面算术表达式的值。
(1)x+a%3*(int)(x+y)%2/4,设x=2.5,a=7,y=4.7;(2)(float)(a+b)/2+(int)x%(int)y,设a=2,b=3,x=3.5,y=2.5。
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语言程序设计教程课后题及模拟题参考答案

main()
{ int x,y;
scanf(“%d,%d”,&x,&y);
if (x*x+y*y>1000)
printf(“%d\n”,(x*x+y*y)/100);
else
printf(“%d\n”,x+y);
}
3.输入一个整数,判断它能否同时被3、5、7整除,并输出“yes”或“no”字样。
a1=a%10 ; a=a/10;
a2=a%10; a=a/10;
a3=a%10;
printf(“%d%d%d\n”, a1, a2, a3);
}
4.编写程序,读入3个double型数据,求它们的平均值,保留此平均值小数点后1位数,对小数点后第2位数进行四舍五入,最后输出结果。
#include "stdio.h"
7. (1)10,6,4 (2)6,9,15 (3)3,60,83
8. 55
习题3
3
1-5BDABC6-10ADCAC 11-12BB
3
1.3
2.0261
3.0x10
4. 2, 1互换a,b的值
5.6.6
6.–003
8.7
7.5.0,4,c=3<Enter>
8.i=10,j=20<Enter>
9.(1) 65
#include "stdio.h"
main()
{ float a, b, h, s;
a=10;b=20;
h=5;s=(a+b)*h/2;
printf("s=%f\n" , s );
大学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.。
(word完整版)C语言程序设计课后习题1-8参考答案

C语言程序设计课后习题1—8参考答案习题1参考答案一、简答题1、冯诺依曼计算机模型有哪几个基本组成部分?各部分的主要功能是什么?答:冯诺依曼计算机模型是由运算器、控制器、存储器、输入设备、输出设备五大功能部件组成的。
运算器又称算术逻辑部件,简称ALU,是计算机用来进行数据运算的部件。
数据运算包括算术运算和逻辑运算。
控制器是计算机的指挥系统,计算机就是在控制器的控制下有条不紊地协调工作的.存储器是计算机中具有记忆能力的部件,用来存放程序和数据.输入设备是用来输入程序和数据的部件。
输出设备正好与输入设备相反,是用来输出结果的部件。
2、简述计算机的工作原理。
答:计算机的工作原理可简单地概括为:各种各样的信息,通过输入设备,进入计算机的存储器,然后送到运算器,运算完毕把结果送到存储器存储,最后通过输出设备显示出来。
整个过程由控制器进行控制。
3、计算机软件系统分为哪几类?答:软件内容丰富,种类繁多,通常根据软件用途将其分为两大类:系统软件和应用软件。
系统软件是指管理、监控、维护计算机正常工作和供用户操作使用计算机的软件。
这类软件一般与具体应用无关,是在系统一级上提供的服务。
系统软件主要包括以下两类:一类是面向计算机本身的软件,如操作系统、诊断程序等。
另一类是面向用户的软件,如各种语言处理程序(像BC、VC等)、实用程序、字处理程序等。
在操作系统的基础上运行。
4、什么叫软件?说明软件与硬件之间的相互关系。
答:软件是指计算机程序及有关程序的技术文档资料。
两者中更为重要的是程序,它是计算机进行数据处理的指令集,也是计算机正常工作最重要的因素。
在不太严格的情况下,认为程序就是软件。
硬件与软件是相互依存的,软件依赖于硬件的物质条件,而硬件则需在软件支配下才能有效地工作.在现代,软件技术变得越来越重要,有了软件,用户面对的将不再是物理计算机,而是一台抽象的逻辑计算机,人们可以不必了解计算机本身,可以采用更加方便、更加有效地手段使用计算机。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
s1+=a[i][i];
}
printf("s1=%d\t",s1);
for(i=0;i<5;i++)
{
s2+=a[i][4-i];
}
printf("s2=%d\t",s2);
for(i=0;i<5;i++)
{
s3=s3+a[i][0]+a[i][4];
}
for(j=0;j<5;j++)
{
s3=s3+a[0][j]+a[4][j];
代码如下:
#include<stdio.h>
#define N 10
void main()
{
char a[N],*p=a;
int i,j;
printf("请输入带空格的字符:");
gets(p);
for(i=0;i<N;i++) //删除空格
{
if(p[i]==32) //先判断该字符是否为空格,如果该字符是空格,则将该字符后面的字符统一向前移动一个位置。直到所有空格被删除为止。
r=a%b;
if(r==0)
printf("最大公约数=%d",b);
else
{
do
{
a=b;
b=r;
r=a%b;
}while(r!=0);
printf("最大公约数=%d",b);
}
}
第五章:
第一题:编程计算矩阵a[5][5]主对角线元素之和,此对角线元素之和和周边元素之和。
代码如下:
#include<stdio.h>
}
if(j==0)
printf("查无此人\n");
}
第二题:用结构数组存放一个数据库,含10个人的考试成绩,包括姓名,数学,计算机,英语,体育和总分,其中,总分由程序自动计算。将总分按从低到高排序。
代码如下:
#include<stdio.h>
#define cj(x,y) {t=x;x=y;y=t;}
}
printf("s3=%d\t",s3);
}
第三题:编制程序统计一个字符串中各种小写字母的个数
代码如下:
# include<stdio.h>
#define m 80
void main()
{
char a[m],b;
int i,j=0;
printf("请输入字符串:");
gets(a);
for(i=0;i<m;i++)
{b=a[i];
if(b>='a'&&b<='z')
j++;
}
printf("输入的字符中小写字母个数为:%d个\n",j);
}
第六章:
第一题:编一个程序,用指针将一个一维数组中的n个整数作如下处理:顺序将前面各数后移m个位置,是最后面的m个数变成最前面的m个数。如:1,3,5,7,9,顺序后移两个位置后变为7,9,1,3,5.
min<c?min:min=c;
max>c?max:max=c;
}
printf("min=%d,max=%d\n",min,max);
}
第三题:编程计算1!+2!+3!+…+20!
代码如下:
# include<stdio.h>
void main()
{
int i=0;
double a,b;
a=1,b=0;
代码如下:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define N 10
void main()
{
int a[N],m,b,i,j,*p=a;
printf("请输入后移的个数:");
scanf("%d",&m);
b=m;
srand(time(NULL));
do
{i++;
a=a*i;
b=b+a;
}while(i<20);
printf("%f\n",b);
}
第四题:编程打印出100以内所有素数。
代码如下:
#include <stdio.h>
void main()
{
int i,n,a;
for(n=2;n<=100;n++)
{i=2;
do
{
a=n%i;
i++;
printf("删除空格后的字符为:");
puts(p);
}
第四题:编一个程序,用指针操作将一个字符串反序存放。
代码如下:
#include<stdio.h>
#include<string.h>
#define JH(x,y) t=x;x=y;y=t;
#define N 10
void main()
{
char a[N],*p=a,t;
for(j=i;p[j];j++)
{
p[j]=p[j+1];
if(p[j+1]!=32) //为防止连续的空格
i=i-1;
}
}
/*for(i=j=0;p[i];i++) //从第一个开始检测是否为空格,将所有非空格字符保留下来
{
if(p[i]!=32)
p[j++]=p[i];
}
p[j]='\0';
*/
}
qz(a,&m,&n);
printf("%2d行%2d列%5d",m+1,n+1,a[m][n]);
}
.h文件中的代码:
void qz(int (*p)[10],int *a,int *b)
{
int i,j,max;
max=p[0][0];
for(i=0;i<10;i++)
for(j=0;j<10;j++)
for(i=0;i<N;i++)
{
a[i]=rand()%101;
}
printf("后移前的数为:");
for(i=0;i<N;i++)
{
printf("%5d",a[i]);
}
/*每一趟先将第一个数标记,
后从第二个数开始将每一个数前移一个位,
然后将标记的数放到最后一位。
for(i=0;i<m;i++)
scanf("%d",&n);
srand(time(NULL));
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=rand()%101;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%5d",a[i][j]);
printf("\n");
代码如下:
#include<stdio.h>
void main()
{
int n;
double s,qiuhe(int n);
printf("请输入一个数:\n");
scanf("%d",&n);
s=qiuhe(n);
printf("该数累加之和为:\n%f\n",s);
}
double qiuhe(int n)
if(a==0)
break;
}while(i<n);
if(!a==0)
printf("%3d",n);
}
}
第五题:编制程序用辗转相除法求整数A和B的最大公约数。
代码如下:
# include<stdio.h>
void main()
{
int a,b,&a,&b);
a<=b?t=a,a=b,b=t:a=a,b=b;
{
int i;
for(i=0;i<N;i++)
{
if(a[i]>='a'&&a[i]<='z')
a[i]=toupper(a[i]);
else if(a[i]>='A'&&a[i]<='Z')
a[i]=tolower(a[i]);
else if(a[i]==0)
break;
}
}
第四题:用递归的方法求1+2+3+4+…+n的和。
代码如下:
#include<stdio.h>
void main()
{
int a,panduan(int a);