C补充练习题—程序.docVIP

  • 165
  • 0
  • 约1.54万字
  • 约 18页
  • 2017-08-26 发布于河南
  • 举报
《C语言程序设计》补充练习题-程序题 第2章 一、阅读程序写运行结果题 1.#include stdio.h void main (void) {char c1=’a’,c2=’b’,c3=’c’,c4=‘\101’,c5=‘\116’; printf(“a%c b%c\tc%c\tabc\n.”,c1,c2,c3); printf(“\t\b%c %c”,c4,c5); } 2.#includestdio .h void main (void) {int c1,c2: c1=97;c2=98; printf(“%c%c\n”,c1,c2); printf(“%d%d\n’’,c1,c2); } 3.#includestdio.h void main(void) {int i,j,m,n; i= 8;j=10; m=++i;n=j++; printf(‘‘%d,%d,%d,% d”.,i,j,m,n); } 4.#includestdio.h void main(void) {int a=1,b=2,c=3; a=b;b=c;c=a; printf(“a=%d,b=%d,c=%d\n”,a,b,c);} 5.#include stdio.h void main (void) {int a,b,c; a=(b=(c= 3)*5)*2-3; printf(“a=%d;b=%d;c=%d\n”,a,b,c); } 第3章 一、阅读程序写运行结果题 1.#include stdio.h void mian (void) {int a=5,b=10; float x=34.73125; char c=’A’; printf(“%3d%3d\n”,a,b); printf(“%d,%f\n”,a,x); printf(”%7.2f,%9.4f\n”,x,x); printf(.”%c,%d”,c,c); printf(“%s,%l0s\n”,” computer”,” computer”); } 二、程序设计题 1.编写程序,用getchar()函数读入两个字符给c1, c2.然后分别用putchar()函数和printf()函数输出这两个字符,并思考以下问题: (1)变量c1, c2应定义为字符型还是整型?或两者皆可? (2)若要求输出c1、c2值的ASCII码,应如何处理。 第4章 一、阅读程序写运行结果题 1.若从键盘上输入“Next↙”,写出下列程序运行结果。 #includestdio.h void main(void) {char c; c=getchar(); if(c=‘a’ c=‘w’|| c=‘A’ c=‘W’) c=c+3; else if((c=‘x’ c=‘z’)|| (c=‘x’c=‘z’)) c=c- 23; printf(“%\n”,c); } 2.写出下列程序运行结果。 #includestdi0.h void main(void) {int x=1,y=0,a=0,b=0; switch(x) {case 1:switch (y) {case 0:a++;break; case 1:b++;break; } case 2:a++;b++;break; case 3:a++;b++; } printf(“a=%d,b=%d\n”,a,b); } 二、程序设计题 1.编写运输公司对用户计算运费程序。距离(S.单位为 km)越远,每公里运费越低。标准如下: S250 没有折扣 250,S500 2%折扣 500}S1000 5%折扣 1 000-S2 000 8%折扣 2 000,S3 000 10%折扣 3 000}S 15%折扣 设每公里每吨货物的基本运费为P,货物重为w,距离为S,折扣为d.则总运费f计算公式为:f=PWS(1-d) 第5章 一、阅读程序写运行结果题 1.写出下列程序运行结果。 void main(void) {int i; for(i=1;i6;i++) {if(i%2) printf(“#”); else continue; printf(“$”); } printf(“\n

文档评论(0)

1亿VIP精品文档

相关文档