C-Primer-Plus第六版中文版习题答案.pdf
《C-Primer-Plus第六版中文版习题答案.pdf》由会员分享,可在线阅读,更多相关《C-Primer-Plus第六版中文版习题答案.pdf(123页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C Primer Plus 第六版中文版习题答案 Github:zhayujie/C-Primer-Plus 第一章 1.#include int main(void)double inch,cm;printf(Please input the inches:);scanf(%lf,&inch);cm=inch*;printf(%g cmn,cm);return 0;第二章 3.#include int main(void)int days,years=21;,days=years*365;printf(我的年龄是%d 岁,%d 天n,years,days);return 0;4.|#incl
2、ude void jolly(void);void deny(void);int main(void)jolly();jolly();deny();return 0;void jolly(void)printf(For hes a jolly good fellow!n);void deny(void)printf(Which nobody can deny!n);5.#include void br(void);.void ic(void);int main(void)br();printf(,);ic();printf(n);ic();printf(n);br();printf(n);re
3、turn 0;void br(void)¥printf(Brazil,Russia);void ic(void)printf(India,China);6.#include int main(void)int toes=10;int toes_2,toes2;toes_2=2*toes;toes2=toes*toes;printf(toes 是%d,toes 的两倍是%d,toes 的平方是%dn,toes,toes_2,toes2);return 0;8.#include(void one_three(void);void two(void);int main(void)printf(sta
4、rting nown);one_three();、void one_three(void)printf(onen);two();printf(threen);printf(done!n);void two(void)printf(twon);第三章 2.#include、int main(void)char ch;printf(please input a number:);scanf(%d,&ch);printf(%cn,ch);return 0;4.#include int main(void)float a;;printf(Enter a floating-point value:);s
5、canf(%f,&a);printf(fixed-point notation:%fn,a);printf(exponential notation:%en,a);return 0;。5.#include int main(void)int age;double seconds;printf(please input your age:);)scanf(%d,&age);seconds=age*;printf(the corresponding seconds are:%en,seconds);return 0;,7.#include int main(void)float inches,cm
6、s;printf(input your height(inch):);scanf(%f,&inches);cms=inches*;【printf(your height(cm):%fn,cms);return 0;8.#include*int main(void)float pint,ounce,soupspoon,teaspoon,cup;printf(input the number of cups:);scanf(%f,&cup);pint=cup/2;ounce=cup*8;soupspoon=ounce*2;teaspoon=soupspoon*3;printf(they are e
7、quivalent of:n%f pintn%f ouncen%f soupspoonsn%f teaspoonsn,pint,ounce,soupspoon,teaspoon);return 0;第四章 1.#include int main(void)char firstname40,lastname40;printf(Input your firstname:);scanf(%s,firstname);printf(Input your lastname:);scanf(%s,lastname);printf(Your name is%s,%sn,firstname,lastname);
8、return 0;2.#include#include int main(void)char name40;int width;$printf(Input your name:);scanf(%s,name);width=strlen(name)+3;printf(%*sn,width,name);#include int main(void)¥float height;char name40;printf(Input your height(cm)and name:);scanf(%f%s,&height,name);height=height/100;printf(%s,you are%.
9、3fm talln,name,height);return 0;5.#include int main(void)float speed,size,time;printf(Input the download speed(Mb/s)and the file size(MB):n);scanf(%f%f,&speed,&size);time=size/speed*;printf(At%.2f megabits per second,a file of%.2f megabytesn,speed,size);printf(downloads in%.2f seconds.n,time);return
10、 0;!6.#include#include int main(void)char firstname40,lastname40;printf(Input your firstname:);scanf(%s,firstname);printf(Input your lastname:);scanf(%s,lastname);printf(%s%sn,firstname,lastname);printf(%*d%*dn,strlen(firstname),strlen(firstname),strlen(lastname),strlen(lastname);printf(%s%sn,firstn
11、ame,lastname);printf(%*d%*dn,?-strlen(firstname),strlen(firstname),-strlen(lastname),strlen(lastname);return 0;7.#include#include?int main(void)double a=;float b=;printf(%.6f%.6fn,a,b);2f,%.12fn,a,b);printf(%.16f,%.16fn,a,b);printf(DBL_DIG:%dn,DBL_DIG);printf(FLT_DIG:%dn,FLT_DIG);)return 0;8.#includ
12、e#define GALLON fn,mile/gallon);printf(Litre per 100 kilometers:%.1fn,,gallon*GALLON/(mile*MILE)*100);return 0;第五章 1.#include#define H_P_M 60 n,min,hour,left);?printf(Enter your next value:);scanf(%d,&min);printf(Good bye!n);return 0;】2.#include int main(void)int num,count;printf(Input a integer:);s
13、canf(%d,&num);count=0;while(count+11)printf(%d,num);num+;printf(n);return 0;3.#include#define DAYS_PER_WEEK 7 n,day,week,left);printf(Next input:);scanf(%d,&day);return 0;4.#include#define CM_PER_FEET f cm=%d feet,%.1f inchesn,cm,feet,inch);printf(Enter a height in centimeters(=0 to quit):);*scanf(%
14、f,&cm);printf(byen);return 0;5.#include int main(void)int count,sum,days;printf(Input the number of days:);scanf(%d,&days);count=sum=0;while(count+days)sum=sum+count;printf(The money you earned:%dn,sum);return 0;6.|#include int main(void)int count,sum,days;printf(Input the number of days:);scanf(%d,
15、&days);count=sum=0;while(count+days)sum=sum+count*count;printf(The money you earned:%dn,sum);return 0;7.#include,void cube(double n);int main(void)double num;printf(Input a number:);scanf(%lf,&num);cube(num);void cube(double n)printf(The cube of%f is%fn,n,n*n*n);8.#include int main(void)int num1,num
16、2;printf(This program computes moduli.n);printf(Enter an integer to serve as the second operand:);scanf(%d,&num1);printf(Now enter the first operand:);#scanf(%d,&num2);while(num20)printf(%d%d is%dn,num2,num1,num2%num1);printf(Enter next number for first operand(=0 to quit):);scanf(%d,&num2);printf(D
17、onen);)9.#include void Temperatures(double fah);int main(void)/double fah,cel,kel;n);void Temperatures(double fah)const double a=,b=,c=,d=;printf(%.2f is%.2f,%.2f K.n,|fah,a/b*(fah-c),a/b*(fah-c)+d);第六章 1.#include#define SIZE 26 int main(void)char chSIZE;int index;for(index=0;indexSIZE;index+)chinde
18、x=a+index;printf(%c,chindex);printf(n);return 0;2.#include int main(void)int i,j;for(i=1;i=5;i+)for(j=1;j=i;j+)printf($);printf(n);return 0;:3.#include int main(void)int i,j;for(i=1;i=6;i+)for(j=0;ji;j+)(printf(%c,F-j);printf(n);return 0;4.、#include#define ROWS 6 int main(void)char ch;int i,j;for(ch
19、=A,i=0;iROWS;i+)for(j=0;j=i;j+)printf(%c,ch+);printf(n);return 0;5.#include#define ROWS 5 int main(void)char ch=A;int i,j;for(i=1;i=ROWS;i+)for(j=1;j=ROWS-i;j+)printf();for(j=0;j=0;j-)printf(%c,ch+j);。printf(n);return 0;6.#include int main(void)int max,min,num;printf(Input the min and max:);scanf(%d
20、%d,&min,&max);printf(%10s%10s%10sn,number,square,cube);|for(num=min;num=max;num+)printf(%10d%10d%10dn,num,num*num,num*num*num);return 0;7.#include、int main(void)double n1,n2;printf(Input two numbers:);while(2=scanf(%lf%lf,&n1,&n2)printf(%fn,(n1-n2)/n1*n2);printf(Input your next pair of numbers:);pri
21、ntf(Bye!n);return 0;9.#include&double calculate(double n1,double n2);int main(void)double num1,num2;printf(Input two numbers:);while(2=scanf(%lf%lf,&num1,&num2)#include int main(void);int lower,upper;int num,sum;printf(Enter lower and upper integer limits:);scanf(%d%d,&lower,&upper);while(lower uppe
22、r)for(sum=0,num=lower;num=upper;num+)sum=sum+num*num;#include#define SIZE 8 int main(void)int numSIZE;int index;printf(Enter 8 integers:);for(index=0;indexSIZE;index+)#include int main(void)double sum1=0,sum2=0;int count,items,sign;printf(Enter the items:);scanf(%d,&items);.=%fn,sum1);printf(-+-+.=%
23、fn,sum2);return 0;】13.#include#define SIZE 8 int main(void)int index,count,numSIZE;for(index=0,count=1;index SIZE;index+)count*=2;numindex=count;#include#define SIZE 8 int main()double num1SIZE,num2SIZE;int index1,index2,index;printf(Enter 8 numbers to the first array:n);for(index1=0;index1 SIZE;ind
24、ex1+)scanf(%lf,&num1index1);#include#include#define SIZE 255 int main(void)(int index;char chSIZE;printf(Enter a line:);for(index=0,scanf(%c,&ch0);chindex!=n;)index+;/scanf(%c,&chindex);#include#define RATE_DAPHNE#define RATE_DEIRDRE n,year,daphne,deirdre);#include#define INITIAL_MONEY 100 n,year);r
25、eturn 0;。18.#include#define INITIAL_NUMBER 5#include int main(void)$char ch;int n_space=0;n);while(ch=getchar()!=#)if(ch=)n_space+;else if(ch=n)n_newline+;。else n_others+;printf(Spaces:%d,newlines:%d,others:%dn,n_space,n_newline,n_others);return 0;2.#include#define CHARS_PER_LINE 8#include int main(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Primer Plus 第六 中文版 习题 答案
限制150内