2022年C语言教程经典程序设计题 .pdf





《2022年C语言教程经典程序设计题 .pdf》由会员分享,可在线阅读,更多相关《2022年C语言教程经典程序设计题 .pdf(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、http:/ C 语言教程经典程序设计题1、有一个函数:y= #include main() int x,y; printf(input x:); scanf(%d,&x); if(x1) y=x; else if(x10) y+2*x-1; else y=3*x-1; printf(y=%dn,y); 运行结果: input x:21 y=62 根据所输入的年份和月份,计算该月有多少天?#include main() int year,month,day; printf(input the year and month:); scanf(%d,%d,&year,&month); switch
2、(month) case 4: case 6: case 9: case 11:day=30;break; case 2:day=(year%4=0&year%100!=0|year%400=0?29:28);break; (& 和|的优先性?) default:day=31;break; printf(the month is %d dayn,day); 运行结果:input the year and month:2006,2 the month is 28 day 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理
3、 - - - - - - - 第 1 页,共 8 页 - - - - - - - - - input the year and month:2006,12 the month is 31 day 输入 4 个整数,要求按大小顺序输出。#include main() int a,b,c,d,t; printf(input a,b,c,dn:); scanf(%d%d%d%d,&a,&b,&c,&d); if(ab) t=a;a=b;b=t; if(ac) t=a;a=c;c=t; if(ad) t=a;a=d;d=t; if(bc) t=b;b=c;c=t; if(bd) t=b;b=d;d=t
4、; if(cd) t=c;c=d;d=t; printf(the result is : %d,%d,%d,%dn,a,b,c,d); 运行结果:input a,b,c,d :8 4 9 6 the result is : 9,8,6,4 所谓“水仙花数”是指一个3 位数,其各位数字的立方和等于该数本身。例如:371 是一个“水仙花数” ,371=33+73+13 #include main() int i,a,b,c,sum; sum=0; for(i=100;i=999;i+) a=i%10; b=i/10-i/100*10; (或 b=i%100/10; )c=i/100; sum=a*
5、a*a+b*b*b+c*c*c; if(i=sum) printf(%4d ,i); 结果:153 370 371 407 . 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 8 页 - - - - - - - - - 编写程序实现一个专家诊断系统。假设系统库中有3 种病例:肺炎、气管炎、感冒,如果咳嗽并发烧则属肺炎;如果咳嗽但不发烧则属气管炎;流鼻涕且不咳嗽属感冒。#include main() char cough,fever,snot; int ill; print
6、f(do you cough:n); scanf(%c,&cough); printf(do you fever:n); scanf(%c,&fever); printf(do you snot:n); scanf(%c,&snot); if(cough= y ) if(fever= y ) ill=1; else ill=2; else if(snot= y ) ill=3; else ill=0; switch(ill) case 1:printf(you get pneumonia);break; case 2:printf(you get tracheitis);break; case
7、 3:printf(you catch a cold);break; default: printf(sorry,see other doctor); 结果:do you cough: y do you fever: y do you snot: n you get tracheitis 编写程序:打印九九乘法表。1、#include 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 8 页 - - - - - - - - - main() int i,j; for(i=1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年C语言教程经典程序设计题 2022 语言 教程 经典 程序设计

限制150内