您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > C-Primer-Plus第六版中文版习题答案
CPrimerPlus第六版中文版习题答案Github::yjzha1996@163.com第一章1.#includestdio.hintmain(void){doubleinch,cm;printf(Pleaseinputtheinches:);scanf(%lf,&inch);cm=inch*2.54;printf(%gcm\n,cm);return0;}第二章3.#includestdio.hintmain(void){intdays,years=21;days=years*365;printf(我的年龄是%d岁,%d天\n,years,days);return0;}4.#includestdio.hvoidjolly(void);voiddeny(void);intmain(void){jolly();jolly();deny();return0;}voidjolly(void){printf(Forhe'sajollygoodfellow!\n);}voiddeny(void){printf(Whichnobodycandeny!\n);}5.#includestdio.hvoidbr(void);voidic(void);intmain(void){br();printf(,);ic();printf(\n);ic();printf(\n);br();printf(\n);return0;}voidbr(void){printf(Brazil,Russia);}voidic(void){printf(India,China);}6.#includestdio.hintmain(void){inttoes=10;inttoes_2,toes2;toes_2=2*toes;toes2=toes*toes;printf(toes是%d,toes的两倍是%d,toes的平方是%d\n,toes,toes_2,toes2);return0;}8.#includestdio.hvoidone_three(void);voidtwo(void);intmain(void){printf(startingnow\n);one_three();}voidone_three(void){printf(one\n);two();printf(three\n);printf(done!\n);}voidtwo(void){printf(two\n);}第三章2.#includestdio.hintmain(void){charch;printf(pleaseinputanumber:);scanf(%d,&ch);printf(%c\n,ch);return0;}4.#includestdio.hintmain(void){floata;printf(Enterafloating-pointvalue:);scanf(%f,&a);printf(fixed-pointnotation:%f\n,a);printf(exponentialnotation:%e\n,a);return0;}5.#includestdio.hintmain(void){intage;doubleseconds;printf(pleaseinputyourage:);scanf(%d,&age);seconds=age*3.156e7;printf(thecorrespondingsecondsare:%e\n,seconds);return0;}7.#includestdio.hintmain(void){floatinches,cms;printf(inputyourheight(inch):);scanf(%f,&inches);cms=inches*2.54;printf(yourheight(cm):%f\n,cms);return0;}8.#includestdio.hintmain(void){floatpint,ounce,soupspoon,teaspoon,cup;printf(inputthenumberofcups:);scanf(%f,&cup);pint=cup/2;ounce=cup*8;soupspoon=ounce*2;teaspoon=soupspoon*3;printf(theyareequivalentof:\n%fpint\n%founce\n%fsoupspoons\n%fteaspoons\n,pint,ounce,soupspoon,teaspoon);return0;}第四章1.#includestdio.hintmain(void){charfirstname[40],lastname[40];printf(Inputyourfirstname:);scanf(%s,firstname);printf(Inputyourlastname:);scanf(%s,lastname);printf(Yournameis%s,%s\n,firstname,lastname);return0;}2.#includestdio.h#includestring.hintmain(void){charname[40];intwidth;printf(Inputyourname:);scanf(%s,name);width=strlen(name)+3;printf(%*s\n,width,name);//输入的名和姓中间不能分隔return0;}4.#includestdio.hintmain(void){floatheight;charname[40];printf(Inputyourheight(cm)andname:);scanf(%f%s,&height,name);height=height/100;printf(%s,youare%.3fmtall\n,name,height);return0;}5.#includestdio.hintmain(void){floatspeed,size,time;printf(Inputthedownloadspeed(Mb/s)andthefilesize(MB):\n);scanf(%f%f,&speed,&size);time=size/speed*8.0;printf(At%.2fmegabitspersecond,afileof%.2fmegabytes\n,speed,size);printf(downloadsin%.2fseconds.\n,time);return0;}6.#includestdio.h#includestring.hintmain(void){charfirstname[40],lastname[40];printf(Inputyourfirstname:);scanf(%s,firstname);printf(Inputyourlastname:);scanf(%s,lastname);printf(%s%s\n,firstname,lastname);printf(%*d%*d\n,strlen(firstname),strlen(firstname),strlen(lastname),strlen(lastname));printf(%s%s\n,firstname,lastname);printf(%*d%*d\n,-strlen(firstname),strlen(firstname),-strlen(lastname),strlen(lastname));return0;}7.#includestdio.h#includefloat.hintmain(void){doublea=1.0/3.0;floatb=1.0/3.0;printf(%.6f%.6f\n,a,b);//左侧double型右侧float型printf(%.12f,%.12f\n,a,b);printf(%.16f,%.16f\n,a,b);printf(DBL_DIG:%d\n,DBL_DIG);printf(FLT_DIG:%d\n,FLT_DIG);return0;}8.#includestdio.h#defineGALLON3.758//1gallon=3.785liters#defineMILE1.609//1mile=1.609kilometersintmain(void){floatgallon,mile;printf(Inputmilesandgallons:);scanf(%f%f,&mile,&gallon);printf(Milespergallon:%.1f\n,mile/gallon);printf(Litreper100kilometers:%.1f\n,gallon*GALLON/(mile*MILE)*100);return0;}第五章1.#includestdio.h#defineH_P_M60//1h=60minintmain(void){inthour,min,left;printf(Enterthenumberofminutes:);scanf(%d,&min);while(min0){hour=min/H_P_M;left=min%H_P_M;printf(%dminutesis%dhoursand%dminutes.\n,min,hour,left);printf(Enteryournextvalue:);scanf(%d,&min);}printf(Goodbye!\n);return0;}2.#includestdio.hintmain(void){intnum,count;printf(Inputainteger:);scanf(%d,&num);count=0;while(count++11){printf(%d,num);num++;}printf(\n);return0;}3.#includestdio.h#defineDAYS_PER_WEEK7//一周7天intmain(void){intday,week,left;printf(Inputthenumberofdays:);scanf(%d,&day);while(day0){week=day/DAYS_PER_WEEK;left=day%DAYS_PER_WEEK;printf(%ddaysare%dweeks,%ddays.\n,day,week,left);printf(Nextinput:);scanf(%d,&day);}return0;}4.#includestdio.h#defineCM_PER_FEET30.48//1feet=30.48cm#defineCM_PER_INCH2.54//1inch=2.54cmintmain(void){intfeet;floatcm,inch;printf(Enteraheightincentimeters:);scanf(%f,&cm);while(cm0){feet=(int)(cm/CM_PER_FEET);inch=(cm-feet*CM_PER_FEET)/CM_PER_INCH;printf(%.1fcm=%dfeet,%.1finches\n,cm,feet,inch);printf(Enteraheightincentimeters(=0toquit):);scanf(%f,&cm);}printf(bye\n);return0;}5.#includestdio.hintmain(void){intcount,sum,days;printf(Inputthenumbe
本文标题:C-Primer-Plus第六版中文版习题答案
链接地址:https://www.777doc.com/doc-4598317 .html