ImageVerifierCode 换一换
格式:DOCX , 页数:69 ,大小:101.27KB ,
资源ID:3301123      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3301123.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C语言习题册.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C语言习题册.docx

1、C语言习题册第一章 C语言基础知识1. 读程序(1) 阅读程序,写出运行结果。#include main() int a,b,c,d; a=26; b=6; c=a/b; d=a%b; printf(%d/%d=%d,%d%d=%dn,a,b,c,a,b,d);(2) 阅读程序,写出运行结果。#include main() char x=a,y=98; printf(%dtb%cn,x,y);(3) 阅读程序,写出运行后的结果。#include main() int a=5,b=12,x,y; x=a*=4; y=b-; printf(%d,%dn,x,y); (4) 阅读程序,写出运行后的结

2、果。 #include main() int a=5,b; char c=A; float d; b=c; d=a; printf(%d,%f,%d,%cn,b,d,a,c); (5) 阅读程序,写出运行后的结果。 #include main() int i=28,j; char a=a,c=c; float f=23.69; double d,e=14.6; j=a=c-i; d=i*f-e; printf(%d,%dn,i,j); printf(%c,%cn,a,c); printf(%fn,f); printf(%lfn,d);(6) 阅读程序,写出运行后的结果。 #include ma

3、in() int i=1000; printf(%dn,i+); printf(%dn,+i); printf(%dn,i-); printf(%dn,-i); 2. 编程题(1) 编写程序,从键盘上输入学生的三门课程成绩,求总成绩、平均成绩。(2) 编写程序,将a=120.3456按小数、整数部分各占3位,且靠左对齐的格式输出。(3) 编写程序,从键盘上输入一个大写字母,要求用小写字母输出。(提示:大写字母比小写字母的小32)(4) 编写程序,用getchar函数读入任意两个字符给c1、c2,然后分别用putchar函数和printf函数输出这两个字符。还要求输出这两个字符的ASCII值。(

4、5) 编写程序,有一个梯形的上底为10,下底为20,高为10,求梯形的面积。(6) 编写程序,已知a=8,b=10.4,求ax+6=0的x的值。(7) 编写程序,已知摄氏温度25度,求其华氏温度。(f=9/5c+32)(8) 编写程序,已知一整数数字5768,利用整数除法求商和余数运算符,求各位数字之和。(求5+7+6+8的值)第二章 选择结构1. 读程序(1) 阅读程序,写出运行结果。#include main( ) char c=A; if (0=c & c=9) printf(YES); else printf(N0);(2) 阅读程序,当输入变量a的值为1,变量b的值为2,写出运行结果

5、。#include main( ) int a, b, t=0; scanf(%d%d,&a,&b); if(a=2) t=a, a=b,b=t; printf(a=%d,b=%dn, a,b);(3) 阅读程序,写出运行后的结果。#includemain() int a=2,b=-1,c=2; if(ab) if(b0) c=0; else c+=1; printf(%dn,c); (4) 阅读程序,写出运行后的结果。 #includemain() int a,b,c; a=1; b=2; c=3; if(ab) if(ac) printf(%d,a); else printf(%d,b);

6、 printf(%dn,c); (5) 阅读程序,写出运行后的结果。 #includemain() int a=-1, b=1,k; if(+a0)&!(b-=0) printf(%d %dn,a,b); else printf(%d %dn,b,a); (6) 阅读程序,写出运行后的结果。 #includemain() int a=10, b=0; if (a=12) a=a+1; b=b+1; else a=a+4; b=b+4; printf(a=%d;b=%dn,a,b); (7) 阅读程序, 当从键盘输入字母A时,写出运行后的结果。 #includemain() char ch; c

7、h=getchar(); switch (ch) case 65: printf(%c,A); case 66: printf(%c,B); default: printf(%sn,other); (8) 阅读程序。 当输入为:-1 -2,程序的运行结果。 当输入为:1 0,程序的运行结果。 为了输出n=4,变量a和b应具备条件。#include main() int a,b,m,n; scanf(%d%d,&a,&b); m=n=1; if(a0) m=m+n; if(ab) n=2*m; else if(a=b) n = 5; else n=m+n; printf(m=%d n=%dn,m

8、,n); 2. 编程题(1) 编程判断输入整数x的正负性和奇偶性。(2) 求两数中的较大值。(3) 输入被除数和除数,求商。(4) 比较两个整数的大小。(5) 已知银行整存整取存款不同期限的月息利率分别为: 063% 期限一年 066% 期限=年 月息利率= 069% 期限三年 075% 期限五年 084% 期限八年 要求输入存钱的本金和期限,求到期时能从银行得到的利息与本金的合计。(6) 通过键盘输入字符,将输入的字符分为控制、数字、大写字母、小写字母和其他字符等五类。(7) 在屏幕上显示一张时间表,操作人员根据提示进行选择,程序根据输入的时间序号显示相应的问候信息。(8) 简单计算器。请编

9、写一个程序计算表达式:datal op data2的值。其中op为运算符+、*、。(9) 输入年份year和月month,求该月有多少天。判断是否为闰年,可用如下C语言表达式:year%4=0 & year%100!=0 | year%400=0。若表达式成立(即表达式值为1),则year为闰年;否则,表达式不成立(即值为0),year为平年。(10) 对输入的行、单词和字符进行计数。我们将单词的定义进行化简,认为单词是不包含空格、制表符(t)及换行符的字符序列。例如:“a+b+c”,认为是1个单词,它由5个字符组成。又如:“xy abc”,为2个单词,6个字符。(11) 从键盘输入任意的字符

10、,按下列规则进行分类计数。第类 0,1,2,3,4,5,6,7,8,9第=类 +,*,%,=第三类 其它字符当输入字符时先计数,然后停止接收输入,打印计数的结果。(12) 输入10个整数,求其中正数的个数及平均值,精确到小数点后两位。(13) 已知一个首项大于0的等差数列的前四项和为26,前四项的积为880,求此数列。 (14) 输入a、b、c三个整数,求最小值min。(15) 输入a、b、c、d四个整数,求最小值min和最大值max。 (16) 编写程序,输入三角型的三条边长,求其面积。注意:对于不合理的边长输入要输出数据错误的提示信息。第三章 循环结构1. 读程序(1) 阅读程序,分别写出

11、i,j,k 运行后的结果。 #include main( ) int a=10,b=5,c=5,d=5; int i=0,j=0,k=0; for( ;ab;+b) i+; while(a+c) j+; do k+; while(ad+); printf(“i=%d,j=%d,k=%dn”, i, j, k); (2) 阅读程序,写出运行后的结果。 #include main() int n=4; while(n-) printf(“%dn”,-n); (3) 阅读程序,写出运行后的结果。 #include main() int i,j; for(i=0,j=10;ij;i+=2,j-); p

12、rintf(“i=%dn”,i); printf(“j=%dn”,j); (4) 阅读程序,写出运行后的结果。 #includemain() int i=0,j=0,k=0,m; for(m=0;m4;m+) switch(m) case 0: i=m+; case 1: j=m+; case 2: k=m+; case 3: m+; printf(n%d,%d,%d,%dn,i,j,k,m); (5) 阅读程序,写出运行后的结果。 #include main() char i,j; for(i=0,j=9;ij;i+,j-) printf(“%c%c”,i,j); printf(“n”);

13、(6) 阅读程序,写出运行后的结果。 #include main() int k,j,m; for(k=5;k=1;k-) m=0; for(j=k;j=5;j+) m=m+k*j; printf(“%dn”,m); (7) 阅读程序,写出运行后的结果。 #include main() int i,j; float s; for(i=7;i4;i-) s=0; for(j=i;j3;j-) s=s+i*j; printf(“%fn”,s); (8) 阅读程序,写出运行后的结果。 #include main() int x=10,y=10,i; for(i=0;x8;y=+i) printf(x

14、=%d,y=%dn,x-,y); (9) 阅读程序,写出运行后的结果。 #include main() int k=1;char c=A; do switch(c+) case A: k+; break; case B: k-; case C: k+=2; break; case D: k=k%2; continue; case E: k=k*2; break; default: k=k3; k+; while(cF);printf(“k=%dn”,k); (10) 阅读程序, 自第一列开始输入数据:2473,写出运行后的结果。 #include main() int s; while(s=g

15、etchar()!=n) switch(s-2) case 0:case 1: putchar(s+4); case 2: putchar(s+4); break; case 3: putchar(s+3); default: putchar(s+2); break; printf(“n”); (11) 若从终端上由第一列开始输入数据:right?,写出程序运行后的结果。 #include main() char c; c=getchar(); while(c!=?) putchar(c); c=getchar(); (12) 阅读程序,写出运行后的结果。 #include main( ) i

16、nt i=1; while(i=15) if( +i%3!=2 ) continue; else printf(“%d ” ,i); printf(“n”); (13) 阅读程序,写出运行后的结果。 #include main() int i=0,j=0; while(i10) i+; while(j+10); printf(“i=%d,j=%dn”,i,j); (14) 阅读程序,写出运行后的结果。#include main() int i,j,k; char space= ; for(i=0;i=2;i+) for(j=1;j=i;j+) printf(“%c”,space); for(k

17、=0;k=2;k+) printf(“%c”,*); printf(“n”); (15) 阅读程序,写出运行后的结果。#include void main() int j,i,k=0; for(j=11;j=30;j+)if(k%10=0) printf(“n”); for(i=2;i=j-1 ) printf(“%dt”,j); k+; (16) 阅读程序,输入数据:abcd,写出运行后的结果。#include main() char c; while(c=getchar()!=n) printf(%4d,c); printf(n);2. 程序填空(1) 下面函数用来计算x的y次方,其中y为

18、整型变量且y=0。 float power(float x,int y) float z; for(z=1;y0;y_(1)_) z_(2)_; return(z);(2) 已知:任意一个正整数的立方都可以写成一串连续奇数的和。例如: 13*13*13=2197=157+159+177+179+181 下列程序可以验证上述定理。 #include main() long int n,i,k,j,sum; printf(“Enter n=“); scanf(“%d”,&n); k=n*n*n; for(i=l;ik/2;i+=2) for(j=i,sum=0;_(1)_; j+=2) sum+=

19、j; if(_(2)_)printf(“%ld*%ld*%ld=%ld=form%ld to%ldn”,n,n,n,sum,i,_(3)_); (3) XYZ+ YZZ532下列程序的作用是求以下算式中X、Y、Z的值。 #include main() int x,y,z,i,result=532; for(x=1; _(1)_;x+) for(y=1;_(2)_;y+) for(z=_(3)_ ; _(4)_;z+) i=(_(5)_)+(100*y+10*z+z); if(i=result) printf(“x=%d,y=%d,z=%dn”,x,y,z); (4) 华氏和摄氏的转换公式为C=

20、59*(F-32),其中C表示摄氏的温度,F表示华氏的温 度。要求输出从华氏0度到华氏300度,每隔20度输出一个值。#include main() int upper,step; float fahr=0,celsius; upper=300;step=20; while(_(1)_upper) _(2)_; printf(“%4.0f,%6.1fn”,fahr,celsius); _(3)_; (5) 下面的程序输出3到100之间的所有素数。 #include main() int i,j; for(i=3;i=100;i+) for(j=2;j=i-1;j+) if(_(1)_) bre

21、ak; if(_(2)_) printf(“%4d”,i); (6) 下面的函数gcd(a,b)计算两个整数a和b的最大公因子。 gcd(int num,int den) int temp; while(den) temp=_(1)_; num=den; den=temp; return(_(2)_);(7) 函数primedec(m)是求整数 m的所有素数因子,并输出。例如:m为120时,输出的素数因子为:2, 2, 2, 3, 5, 程序如下: primedec(int m) int k=2; while(k=m) if(m%k _(1)_ ) printf(“%d,”, k); _(2)

22、_; else _(3)_; (8) 下面的程序对从终端上接受的正文分别进行字符、字、行计数,并输出。例如,输入: now I am preparing for C language test 则结果显示: line=3 word=8 charactor=39 #include main() int c,n_line=0,n_word=0,n_char=0,inword=0; while(c=getchar()!=EOF) +n_char; if(c=n) +n_line; if (c= |c=t |_(1)_) _(2)_; elseif (inword=0) _(3)_; +n_word;

23、 printf(“line=%d word=%d character=%dn”,n_line,n_word,n_char); 3. 编程题(1) 从键盘输入十个整数,求这十个整数之和。(2) 从键盘中读入一系列字符,直到输入字母“a”时才停止。(3) 对输入的行和字符进行计数。在计算机中,一行是以一个回车符(n)作为行结束标记的,这样在程序中可以通过搜索n对行进行计数。在UNIX操作系统中,一般有CTRL+D作为文件结束标记,其字符码为l。当输入CTRL+D时表示文件输入结束,停止计数。(4) 输出如下图所示的下三角形乘法九九表。 1 2 3 4 5 6 7 8 9 - - - - - - -

24、 - - - - - - - - - - - - - - -1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 649 18 27 36 45 54 63 72 81 (5) 求1到10的阶乘。(6) 求菲波那奇数列:数列1、1、2、3、5、8、13、21、,是著名的菲波那奇数列,其递推通项公式为: l1 (n=l,2) = + (n=3)(7) 为求出第N项的值,请编写程序。 (8) 输入一个正整数,要求以相反的顺序输出该数。例如输入12345,输出位5432

25、1。 (9) 求555555的约数中最大的三位数是多少?(10) 输入10个整数,求其中正数的个数及平均值,精确到小数点后两位。(11) 输入n值,打印下列高为n的等腰三角形。 * * * * * 当n=6时(12) 输入n值,请编程输出如下图形(例n=3时)。 * * * * * * * *(13) 编程打印数字金字塔。 l 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 5 6 5 4 3 2 1 1 2 3 4 5 6 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 7 6 5 4 3 2 11 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 (14) 编程输出下列高度为n的图形。 1 3 6 10 1

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1