- 7
- 0
- 约4.39千字
- 约 12页
- 2018-01-26 发布于河南
- 举报
谭浩强版C程序设计_习题课1-第3章部分习题
4.字符输入输出 #include iostream using namespace std; int main ( ) {char c1,c2; //int c1=97,c2=98; cout请输入两个字符c1,c2:; c1=getchar(); //将输入的第一个字符赋给c1 c2=getchar(); //将输入的第二个字符赋给c2 cout用putchar函数输出结果为:; putchar(c1); putchar(c2); coutendl; cout用cout语句输出结果为:; coutc1c2endl; return 0; } 用getchar函数时,应当连续输入两个字符,再按回车键 12.逆序输出一个数的各位数 #include iostream using namespace std; int main () {long int num; int indiv,ten,hundred,thousand,ten_thousand,place; /*分别代表个位,十位,百位,千位,万位和位数*/ coutenter an integer(0~99999):; cinnum; if (num9999) place=5; else if (num999) place=4; else if (num99) place=3; else if (num9) place=2; else place=1; coutplace=placeendl; //计算各位数字 ten_thousand=num/10000; thousand=(int)(num-ten_thousand*10000)/1000; hundred=(int)(num-ten_thousand*10000-thousand*1000)/100; ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10; indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10); coutoriginal order:; switch(place) {case 5:coutten_thousand,thousand,hundred,ten,indivendl; coutreverse order:; coutindivtenhundredthousandten_thousandendl; break; case 4:coutthousand,hundred,ten,indivendl; coutreverse order:; coutindivtenhundredthousandendl; break; case 3:couthundred,ten,indivendl; coutreverse order:; coutindivtenhundredendl; break; case 2:coutten,indivendl; coutreverse order:; coutindivtenendl; break; case 1:coutindivendl; coutreverse order:; coutindivendl; break; } return 0; } 14.由小到大顺序输出4个整数 int main () {int t,a,b,c,d; coutenter four numbers:; cinabcd; couta=a, b=b, c=c,d=dendl; 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;} if (cd) {t=c; c=d; d=t;} coutthe sorted sequence:endl; couta, b, c, dendl; return 0; } 15.求最大公约和最小公倍数 int ma
您可能关注的文档
最近下载
- 项目可行性研究报告大纲.pptx VIP
- 小学体育五年级下册教案(最全).doc VIP
- 照顾老人保姆合同范本10篇.docx VIP
- 图形推理专项练习题.FIT).pdf VIP
- 《钢轨超声波探伤系统的设计》【毕业设计论文】.doc VIP
- 2022年广东高考生物试卷真题及答案详解(精校版).pdf VIP
- Panasonic 松下 录像机 DMR-EH59 DMR-EH49 Operating Instructions 操作手册说明书 (英语).pdf
- 迪罗—特马法纤维开松混合设备机械原理.pdf VIP
- 高考英语单词3500乱序版.pdf VIP
- 2024年新课标高考福建高考真题生物试卷(原卷版).docx VIP
原创力文档

文档评论(0)