第2章C语言.doc_第1页
第2章C语言.doc_第2页
第2章C语言.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第2章习题参考答案:1.指出下列常量的数据类型及其在printf( )中的格式说明符。 (1)b 类型:char 说明符:%c (2)1066 类型:int 说明符:%d (3)0x3 类型:unsigned int 说明符:%x (4)2.34e07 类型:double 说明符:%e (5)040 类型:char 说明符:%c (6)6.0f 类型:float 说明符:%f (7)6L 类型:long 说明符:%ld (8)2.9e05L 类型:long double 说明符:%le (9)s 类型:char 说明符:%c (10)012 类型:unsigned int 说明符:%o 2.假设在一个程序开始处有如下声明: int imate=2; long shot=53456; char grade=A; float log=2.71828; 在下面printf( )语句中写上合适的类型说明符: printf( “The odds against the % d were % ld to.n ”, imate, shot); printf( “A score of % f is not an % c grade.n ”, log, grade);3.指出下列程序中的错误并改正。(1)include #include main void main( ) ( float g; h; float g, h; /*在g和h之间应该是逗号*/ float tax, rate; /*无错误*/ g=e21; g=1e21; /*在e之前至少有一个数字*/ tax=rate*g; /*无错误*/ ) (2)void main( int ) / this program is perfect/ 第1行:去掉int,注释应使 用/*和*/ cows, legs, integer; 第3行:int cows, legs; printf(“How many cow legs did you count ?n”); scanf( “%c”, legs); 第5行:scanf(“%d”, &legs); cows=legs/4; printf( “There are %f cows.n”, cows) 第7行:应是%d,不是%f,且语句后加; 正确的程序是:#includevoid main( ) / *this program is perfect*/ int cows, legs; printf(“How many cow legs did you count ?n”); scanf( “%d”, &legs); cows=legs/4; printf( “There are %d cows.n”, cows); 1.假定所有变量都是int型,求出下列每个变量的值。 x=( 12+6 )/2*3; x=27 x=(2+3)*10.5; x=52x=3+2*( x=7/2 ); x=9y=(int)3.8+3.3; y=6(简化为3+3.3)y=x=( 2+3 )/4; x=1, y=1y= 22.0*3/5; y=13(简化为66.0/5即13.2)2.写出下列程序的运行结果 #includevoid main( ) int num=10; 程序运行结果: printf( “%dn”, +num ); 11 printf( “%dn”, num+ ); 11 printf( “%dn”, num- ); 12 printf( “%dn”, num ); 11 #includevoid main( ) char c1,c2; int diff; float num; c1=s; c2=o; diff=c1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论