大学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语言程序设计教程》(第三版)课后习题参考答案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、什么叫软件?说明软件与硬件之间的相互关系。
答:软件是指计算机程序及有关程序的技术文档资料。
两者中更为重要的是程序,它是计算机进行数据处理的指令集,也是计算机正常工作最重要的因素。
在不太严格的情况下,认为程序就是软件。
硬件与软件是相互依存的,软件依赖于硬件的物质条件,而硬件则需在软件支配下才能有效地工作.在现代,软件技术变得越来越重要,有了软件,用户面对的将不再是物理计算机,而是一台抽象的逻辑计算机,人们可以不必了解计算机本身,可以采用更加方便、更加有效地手段使用计算机。
《C语言程序设计》课后习题参考答案
{
t=t+i;
s=s+t;
}
printf("s=%d\n",s);
}
习题
一、选择题
1.B 2.A 3.A 4.D 5.C 6.B 7.A 8.A
二、填空题
1.按行的顺序依次存放的
2.0
3.4
4.6
三、编程题
1.有一个多项式:Pn(x)=a0xn+a1xn-1+…+an
2.0 1
3.1
4.4
5.-1
三、编程题
1.给出等级成绩′A′、′B′、′C′、′D′、′E′,假设,90分以上为′A′,80~89分为′B′,70~79分为′C′,60~69分为′D′,60分以下为′E′,输入一个等级成绩,问属于哪一个分数段。
参考代码如下:
main()
{
int score,m,n;
scanf("%d",&n);
for(i=0;i<5;i++)
if(n>a[i])
continue;
else
break;
for(j=4;j>=i;j--)
a[j+1]=a[j];
a[i]=n;
for(i=0;i<6;i++)
printf("%d,",a[i]);
printf("\n");
}
4.编写程序,在有序的数列中查找某数,若该数在此数列中,则输出它所在的位置,否则输出no found。
二、填空题
1. BASIC、FORTRAN、AL_GOL60和COBOL
《C语言程序设计教程》课后题答案
《C语言程序设计教程》课后题答案第一章一选择题1.A2.B3.C4.D5.B6.C二.填空题1.程序2.算法3.main或主4.编译5.编译6. .obj7.库函数8.文本或ASCII码三、编程题1.参考代码如下:#include <stdio.h>void main(){printf("金\n木\n水\n火\n土\n");}2. 参考代码如下:#include <stdio.h>void main(){ int a,b;scanf("%d%d",&a,&b);printf("%d+%d=%d\n",a,b,a+b);printf("%d-%d=%d\n",a,b,a-b);printf("%d*%d=%d\n",a,b,a*b);printf("%d/%d=%d\n",a,b,a/b);}3. 参考代码如下:#include <stdio.h>void main(){float a,b,h,s;scanf("%f%f%f",&a,&b,&h);s=(a+b)*h/2;printf("s=%f\n",s);}第二章一选择题答案及分析:1.B,略2.A,-8在内存中是以补码(设两个字节)形式存储的3.A,C语言有32个关键字(参见课本第18页),且C语言标识符是区分大小写字母的4.A,略5.D,八进制数据中不能出现数码86.B,字符常量应该用单引号括起来,答案D超出了ASCII取值范围(ASCII的取值范围为[0,255])7.C,该字符串中转义字符有三个:\\、 \22和 \n,普通字符有三个:a、 ,和0,所以字符串长度为68.C,略9.D,C语言没有read函数和%D格式符号,且scanf函数第二个形参为地址列表10.B,根据题意,scanf函数输入数据时分隔符号不应该是逗号,应该是空格或回车符,且输入数据时分一行或几行均可11.A,scanf函数中不允许出现%8.4,%6.2和%8这样的格式符号12.C,既要保证5位小数位,还得保证整数位不变,这样数据12345.67800用10列不能完全显示出来,按C语言规定,12345.67800原样输出13.B,printf函数中格式符号%d,%o,%x表示对应的整型数据分别按十进制,八进制和十六进制输出14.C,按C语言规定,scanf函数形参双引号中,如果包含非格式符号,在输入数据时要求原样输入二.填空题答案及分析:1.int float double(略)2.65,89 ,printf函数中如果格式符号是%d,则输出相应字符的ASCII十进制数值3.a=98,b=765.000000,c=4321.000000,scanf函数中的格式符号%2d%3f%4f,表示将键盘输入的数据9876543210按2,3,4位分割,然后再分别赋给变量a,b,c4.scanf("%lf%lf%lf",&a,&b,&c); double类型的变量对应的格式符号是%lf三、编程题1. 参考代码如下:#include <stdio.h>void main(){int a=97;printf("%c\n",a);printf("%d\n",a);printf("%o\n",a);printf("%x\n",a);}程序分析:通过printf函数中不同的格式符号,即%c(字符),%d(十进制),%o(八进制),%x(十六进制)输出相应的值。
大学生C语言课后习题全部答案详解
\
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程序设计语言课后答案C程序设计语言课后答案C语言是一种广泛使用的计算机编程语言,由丹尼斯·里奇于1972年在贝尔实验室开发。
它以其高效性、灵活性和广泛的应用领域而闻名。
C语言是许多现代编程语言的基础,如C++、Java和C#。
学习C语言不仅能够帮助理解计算机系统的底层工作原理,而且对于掌握其他编程语言也大有裨益。
第一章:C语言基础问题1:C语言的主要特点是什么?答:C语言的主要特点包括:- 简洁的结构,使得程序编写和理解都相对容易。
- 丰富的数据类型,支持多种数据结构。
- 强大的控制语句,如循环和条件语句。
- 支持模块化编程,允许程序分解为多个函数。
- 低级语言特性,如指针,允许直接访问内存地址。
问题2:C语言的基本语法规则有哪些?答:C语言的基本语法规则包括:- 所有的语句必须以分号结束。
- 程序由函数组成,主函数是程序的入口点。
- 变量声明必须指定数据类型。
- 程序必须包含预处理指令`#include`来包含标准库。
- 函数名和变量名区分大小写。
第二章:数据类型和运算符问题3:C语言中的整型数据类型有哪些?答:C语言中的整型数据类型包括:- `int`:标准整数类型。
- `short`:短整型,比`int`占用更少的内存。
- `long`:长整型,比`int`占用更多的内存。
- `long long`:超长整型,用于表示非常大的整数。
问题4:C语言中的算术运算符有哪些?答:C语言中的算术运算符包括:- 加法:`+`- 减法:`-`- 乘法:`*`- 除法:`/`- 模运算:`%`(取余)第三章:控制语句问题5:C语言中的条件语句有哪些?答:C语言中的条件语句包括:- `if`语句:用于在满足特定条件时执行一段代码。
- `if...else`语句:用于在条件为假时执行另一段代码。
- `switch`语句:用于基于不同的情况执行不同的代码块。
问题6:C语言中的循环语句有哪些?答:C语言中的循环语句包括:- `for`循环:用于在给定的条件为真时重复执行一段代码。
(完整word版)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位补码的表示范围是多少?答:0~65535、—128~127、—32768~327675.1968年Dijkstra提出结构化程序设计的思想的原因是什么?简要回答结构化程序设计的经典定义.答:结构化程序设计概念的提出主要是源于程序结构的层次性与模块化使得构造出来的软件具有良好的可理解性和可维护性,随着软件规模的扩大与复杂性的提高,程序的可维护性成为程序设计者们关注的重要问题之一。
如果一个程序的代码块仅仅通过顺序、选择和循环这3种基本控制结构进行连接,并且每个代码块只有一个入口和一个出口,则称这个程序是结构化的。
6.C程序在内存中存储在哪儿?计算机的内存空间是如何分区的?分区存放不同类型的数据的目的是什么?答:C语言程序属于应用程序,程序代码本身存放在应用程序区,程序运行时处理的数据存放在应用程序数据区。
计算机的内存空间主要分为3个区:系统程序区、应用程序区和数据区,其中数据区又分为系统程序数据区和应用程序数据区两类。
C语言教材课后习题参考答案.docx
}
}
}
4、
main()
{int i, a, min, max;
scanf(“%d" , &a);
min=a;max=a;
for(i=2;i<=100;i++)
{ scanf(“,&a);
if (a<min) min=a;
if (a>max) inax=a;
}
printf (<<Max=%d, Min=%d\nv, max, min);
3、存储单元、符号地址、内存地址
4、十、十六、八
5、double(双精度型)
6、8
7、5.500000
8、a二-32768
9、+0017,021,0x11
三、写程序运行结果
3257
32 57
7.8& -345.12,7. 8765,-345.1230
7.87654e+00,-3. 5e+02
a,97, 141,61
main()
{int x, y;
for(x=20;x<=100;x++)
for (y=20;y<=100;y++)
if(x*x+y二二1053&&x+y*y二二873)
printf (i(x=%dy=%d\n” , x, y);
}
7、
main()
{
long int k, g, s=0;
printf ("Please input an integer:,z);
Printf(is not a quadratic);
C语言课后习题答案
C语言课后习题答案5请参照本章例题,编写一个C程序,输出以下信息:**************************Very Good!**************************解:mian(){printf(“**************************”);printf(“\n”);printf(“Very Good!\n”);printf(“\n”);printf(“**************************”);}1.6 编写一个程序,输入a、b、c三个值,输出其中最大值。
解:mian(){int a,b,c,max;printf(“请输入三个数a,b,c:\n”);scanf(“%d,%d,%d”,&a,&b,&c);max=a;if(max<b)max=b;if(max<c)max=c;printf(“最大数为:“%d”,max);}第三章3.6写出以下程序运行的结果。
main(){char c1=’a’,c2=’b’,c3=’c’,c4=’\101’,c5=’\116’;printf(“a%cb%c\tc%c\tabc\n”,c1,c2,c3);printf(“\t\b%c %c”,c4,c5);}解:aaㄩbbㄩㄩㄩccㄩㄩㄩㄩㄩㄩabcAㄩN3.7 要将"China"译成密码,译码规律是:用原来字母后面的第4个字母代替原来的字母.例如,字母"A"后面第4个字母是"E"."E"代替"A"。
因此,"China"应译为"Glmre"。
请编一程序,用赋初值的方法使cl、c2、c3、c4、c5五个变量的值分别为,’C’、’h’、’i’、’n’、’a’,经过运算,使c1、c2、c3、c4、c5分别变为’G’、’l’、’m’、’r’、’e’,并输出。
(完整版)C语言课后题编程标准答案
C语言课后题编程答案所有章节的课后习题的选择题和填空题大家必须熟练掌握,编程题掌握到第九章即可。
希望大家通过课后的编程题熟悉典型的编程算法,掌握基本的编程思路,注意编程细节。
第3章3-17 编写程序,把560分钟换算成用小时和分钟表示,然后进行输出。
#include<stdio.h>main(){int h,m。
h=560/60。
m=560%60。
printf(“560分钟可转换成%d小时%d分钟”,h,m)。
}程序总结:(1)只要在程序中用到系统提供的库函数,必须把库函数所在的头文件用#include命令包含进来。
否则库函数的使用无效。
输入输出库函数的头文件是:stdio.h。
数学函数的头文件是:math.h。
字符处理函数的头文件是:ctype.h。
字符串处理函数的头文件是:string.h。
(2)注意C语言中的“/”和“%”两种运算符。
“/”的运算结果取决于两操作数的类型。
比如:1/2=0(与数学中不同,结果与操作数的类型一致,所以结果只取商值),1.0/2=0.5(除之前2要自动类型转换成 2.0,因为只有同类型的操作数才能进行除运算), 1/2.0=0.5, 1.0/2.0=0.5。
“%”的两个操作数都必须是整数。
(3)printf(“560分钟可转换成%d小时%d分钟”,h,m)。
printf第一个参数要尽量详细,这样可以提高输出结果的可读性,恰当好处的添加提示性信息,可以提高程序的质量。
(4)int h,m。
变量起名要有艺术性,尽量做到见名知意。
3-18 编写程序,输入两个整数,1500和350,求出它们的商和余数并进行输出。
#include<stdio.h>main(){int a,b,m,n。
printf(“请输入两个整数:\n”)。
scanf(“%d%d”,&a,&b)。
m=a/b。
n=a%b。
printf(“%d除以%d商%d余%d”,a,b,m,n)。
c语言全部章节习题答案
c语言全部章节习题答案C语言是一门广泛应用于计算机编程的高级编程语言。
它的简洁和强大使得它成为了许多程序员的首选语言。
然而,学习一门新的编程语言并不总是容易的,特别是对于初学者来说。
为了帮助那些正在学习C语言的人们,本文将提供C语言全部章节习题的答案,以期为读者提供一些指导和帮助。
在学习C语言时,习题是巩固所学知识的重要方式。
通过解决习题,学生可以加深对C语言的理解,并提高他们的编程技能。
然而,有时候习题的解答并不容易找到,特别是对于初学者来说。
因此,本文将提供C语言教材中的全部章节习题的答案,以供读者参考。
在第一章中,我们学习了C语言的基本概念和语法。
习题主要涉及变量的声明和赋值,以及简单的算术运算。
以下是第一章习题的答案:1. 声明一个整型变量x,并将其赋值为10。
答案:int x = 10;2. 声明一个字符型变量ch,并将其赋值为'A'。
答案:char ch = 'A';3. 声明两个整型变量a和b,并将其相加的结果赋值给变量c。
答案:int a = 5;int b = 3;int c = a + b;第二章主要介绍了C语言中的控制结构,如条件语句和循环语句。
以下是第二章习题的答案:1. 编写一个程序,判断一个整数是否为偶数。
如果是偶数,输出"Even",否则输出"Odd"。
答案:#include <stdio.h>int main() {int num;printf("Enter an integer: ");scanf("%d", &num);if(num % 2 == 0) {printf("Even");} else {printf("Odd");}return 0;}2. 编写一个程序,计算1到100之间所有偶数的和。
C语言程序设计实用教程参考答案
C语言程序设计实用教程参考答案第2章课后习题参考答案一、(略)二、单选题1、C2、D3、C4、A5、C6、D7、C8、B9、D 10、A三、填空题1、 12、 8803、 100000104、000011115、111100006、 3 .500000 0四、写程序运行结果1、 2,12、 03、 164、35、 1五、编程题解:设鸡有X只,兔有Y只,根据题意可得方程如下:x+y=a2x+4y=b解方程组可得到:x=(4*a-b)/2y=(b-2a)/s编程如下:#include#includemain( ){int x,y,a,b;scanf(“%d,%d”,&a,&b);x=(4*a-b)/2;y=(b-2*a)/2;printf(“There are %d chicken.\n”,x);printf(“There are %d rabbit.\n”,y);}2、(题意看书上:求三角形面积)#include#includemain( ){int a,b,c;float s ,area;printf(“Please input 3 numbers for triangle:\n”); scanf(“%d,%d,%d”,&a,&b,&c);s=0.5*(a+b+c);area=sqrt(s*(s-a)*(s-b)*(s-c));printf(“area=%f”,area);}第3章课后习题参考答案单选题B 2、BC 3、A 4、D 5、B 6、C7、C 8、C 9、A 10、A 11、C 12、C 13、B 14、C 15、B 16、B1、 a=20,b=40,c=202、 233、684、a=%d ,b=%d5、 1 65 1.5 6.56、a=3.140000,3.1400000e+00,3.140e+00,3.140e+00b=-3.141,-3.1415e+00,-3.1415e+007、x=4 y=11 8 k=4 9 x=4.900000 y=4 10 **********填空题1、 (1) d,e (2) (a>b) (3) (d>c) 输出显示:max=72、(1)k=1;break;(2)k=2;break;(3)k=3;break;(4)k=4;break;(5)k=5;bre ak;3 4、(i%3==0)&&(i%5==0)&&(i%7==0) 5、i=0,j=0,n; scanf(“%d”,&n);四、编程题1.要求从大到小打印三个整数,a,b,c.main(){int a,b,c,t;scanf("%d%d%d",&a,&b,&c);if(a<b)< p="">{ t=a; a=b; b=t;}if(a<c)< p="">if(b<c)< p="">{ t=b; b=c; c=t;}printf("big to small:%d %d %d\n",a,b,c);}2.编程求一元二次方程的根#includemain(){float a,b,c,disc,x1,x2,realpart,imagpart;printf("input canshu a,b,c");scanf("%f,%f,%f",&a,&b,&c);printf("The equation ");if(fabs(a)<=1e-6)printf("is not a 2 ci fangcheng.");elsedisc=b*b-4*a*c;if(fabs(disc)<=1e-6)printf("has two equal roots:%f\n", -b/2*a); else if(disc>1e-6) {x1=(-b+sqrt(disc))/(2*a);printf("has distinct real roots:%f and %f\n",x1,x2); }else{realpart=-b/2*a;imagpart=sqrt(-disc)/(2*a);printf("has complex roots:\n");printf("%f+%fi\n",realpart,imagpart);printf("%f-%fi\n",realpart,imagpart);}}3.main(){float a,r,rate,bonus;printf("input a(jiangjin):");scanf("%f",&a);if(a<500)rate=0;else if(a>=500&&a<1000)rate=(a-500+1)*0.05;rate=(a-1000+1)*0.08+500*0.05;else if(a>=2000&&a<3000)rate=(a-2000+1)*0.1+1000*0.08+500*0.05;elserate=(a-3000+1)*0.15+1000*0.1+1000*0.08+500*0.05; bonus=a-rate;printf("rate=%f,bonus=%f\n",rate,bonus);}3’main(){float a,r,rate,bonus,t;printf("input a(jiangjin):");scanf("%f",&a);t=a/500;if(t>6) t=6;switch((int)(t)){case 0: rate=0; break;case 1: rate=(a-500+1)*0.05; break;case 2:case 5: rate=(a-2000+1)*0.1+1000*0.08+500*0.05; break;case 6: rate=(a-3000+1)*0.15+1000*0.1+1000*0.08+500*0.05; break; } bonus=a-rate;printf("rate=%f,bonus=%f\n",rate,bonus);}4.编程,将2000到3000年之间的闰年输出main(){int y;for(y=2000;y<=3000;y++){if(y%4==0&&y%100!=0||y%400==0)printf("%d ",y);}}5.从键盘输入若干字符,统计其中字母符号(区分大小写),数字符号和其他字符的个数。
- 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);