《C Primer Plus》第六 第十二章编程练习答案.docx
《《C Primer Plus》第六 第十二章编程练习答案.docx》由会员分享,可在线阅读,更多相关《《C Primer Plus》第六 第十二章编程练习答案.docx(12页珍藏版)》请在三一办公上搜索。
1、C Primer Plus第六 第十二章编程练习答案1. #include int critic(void ); int main(intargc, char *argv) intnum=56; int units; printf(How many pounds to a firkin of butter?n); scanf(%d,&units); while (units!=num) units=critic; getchar; return 0; int critic int n; printf(No luck, my friend. Try again.n); scanf(%d, &n)
2、; return n; 2. /*pe12-2a.h*/ #include voidset_mode(int mode); voidget_info; voidshow_info; /*pe12-2a.c*/ #include #includepe12-2a.h int mode; float distance, fuel; voidset_mode(intm) if (m !=0 &m !=1) printf(Invalid mode specified. Mode 1(US) used.n); m=1; mode=m; voidget_info if (0=mode) printf(Ent
3、er distance traveled in kilometers: ); scanf(%f, &distance); printf(Enter fuel consumed in liters: ); scanf(%f, &fuel); else printf(Enter distance traveled in miles: ); scanf(%f, &distance); printf(Enter fuel consumed in gallons: ); scanf(%f, &fuel); voidshow_info float units; if (0=mode) units=100*
4、 (fuel/distance); printf(Fuel consumed in liters: %.1f per 100 kmn, units); else units=distance/fuel; printf(Fuel consumed is %.1f miles per gallonn, units); 3. /*pe12-2a.h*/ #include voidset_mode(int mode); voidget_info(int mode); voidshow_info(int mode, float distance, float fuel); /*pe12-2a.c*/ #
5、include #includepe12-2a.h voidset_mode(intmode) if (mode !=0 &mode !=1) printf(Invalid mode specified. Mode 1(US) used.n); mode=1; get_info(mode); voidget_info(intmode) float distance, fuel; if (0=mode) printf(Enter distance traveled in kilometers: ); scanf(%f, &distance); printf(Enter fuel consumed
6、 in liters: ); scanf(%f, &fuel); else printf(Enter distance traveled in miles: ); scanf(%f, &distance); printf(Enter fuel consumed in gallons: ); scanf(%f, &fuel); show_info(mode, distance, fuel); voidshow_info(intmode, floatdistance, floatfuel) float units; if (0=mode) units=100* (fuel/distance); p
7、rintf(Fuel consumed in liters: %.1f per 100 kmn, units); else units=distance/fuel; printf(Fuel consumed is %.1f miles per gallonn, units); /*pe12-2b.c*/ #include #includepe12-2a.h int main(void) int mode; printf(Enter 0 for metric mode, 1 for US mode: ); scanf(%d, &mode); while(mode=0) set_mode(mode
8、); printf(Enter 0 for metric mode, 1 for US mode: ); printf(-1 to quit): ); scanf(%d, &mode); printf(Done,n); getchar; return 0; 4. #include int count=0; int fun; int main(void) inti=0; intcnt; while (i20) cnt=fun; printf(The function has been called %d times:n, cnt); i+; getchar; return 0; int fun
9、count+; return count; 5. /*main.c*/ #include #includerand0.h int main(void) intStr100; int count; for(count=0; count100; count+) Strcount=rand0; sort(Str); for (count=0; count100; count+) if (count%10=0) putchar(n); printf(%3d , Strcount); getchar; return 0; /*fun.h*/ #include #include int rand0(voi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C Primer Plus C Primer Plus第六 第十二章编程练习答案 Plus 第六 第十二 编程 练习 答案
链接地址:https://www.31ppt.com/p-3171068.html