好文档 - 专业文书写作范文服务资料分享网站

(完整word版)CPrimerPlus第6版编程练习答案(已下载)

天下 分享 时间: 加入收藏 我要投稿 点赞

C Primer Plus Sixth Edition Programming Exercise

Selected Answers

Chapter 2 Programming Exercises

PE 2---1

/* Programming Exercise 2-1 */ #include int main(void)

{ printf(\Mahler\\n\

printf(\printf(\

printf(\0; }

PE 2---3

/* Programming Exercise 2-3 */ #include int main(void)

{ int ageyears; /* age in years */ int agedays; /* age in days */

/* large ages may require the long type */ ageyears = 101; agedays = 365 * ageyears;

printf(\return 0; }

PE 2---4

/* Programming Exercise 2-4 */ #include void jolly(void); void deny(void); int main(void) { jolly();

jolly(); jolly(); deny(); return 0; }

void jolly(void) {

printf(\}

void deny(void) {

printf(\}

PE 2---6

/* Programming Exercise 2-6 */ #include int main(void) { int

toes; toes = 10;

1

C Primer Plus Sixth Edition Programming Exercise

Selected Answers

printf(\

printf(\

printf(\0; }

/* or create two more variables, set them to 2 * toes and toes * toes */

PE 2---8

/* Programming Exercise 2-8 */ #include void one_three(void); void two(void); int main(void) {

printf(\one_three();

printf(\0; }

void one_three(void) {

printf(\two();

printf(\}

void two(void) {

printf(\}

Chapter 3 Programming Exercises

PE 3---2

/* Programming Exercise 3-2 */ #include int main(void) {

int ascii;

printf(\scanf(\

printf(\return 0; }

PE 3---4

/* Programming Exercise 3-4 */ #include int main(void) { float num;

printf(\scanf(\

printf(\printf(\printf(\}

2

C Primer Plus Sixth Edition Programming Exercise

Selected Answers

PE 3---6

/* Programming Exercise 3-6 */ #include int main(void) {

float mass_mol = 3.0e-23; /* mass of water molecule in grams */ float mass_qt = 950; /* mass of quart of water in grams */ float quarts; float molecules;

printf(\scanf(\

molecules = quarts * mass_qt / mass_mol;

printf(\return 0; }

Chapter 4 Programming Exercises

PE 4---1

/* Programming Exercise 4-1 */ #include int main(void) { char

fname[40]; char lname[40];

printf(\scanf(\your last name: \lname); printf(\fname); return 0; }

PE 4---4

/* Programming Exercise 4-4 */ #include int main(void) { float

height; char name[40];

printf(\scanf(\name: \

printf(\ return 0; }

PE 4---7

/* Programming Exercise 4-7 */ #include

#include int main(void)

3

C Primer Plus Sixth Edition Programming Exercise

Selected Answers

{ float ot_f = 1.0 /

3.0; double ot_d = 1.0 / 3.0; printf(\values: \

printf(\printf(\

printf(\printf(\

printf(\}

Chapter 5 Programming Exercises

PE 5---1

/* Programming Exercise 5-1 */ #include int main(void)

{ const int minperhour = 60; int minutes, hours, mins;

printf(\scanf(\ { hours = minutes /

minperhour; mins = minutes % minperhour;

printf(\printf(\&minutes); }

printf(\ return 0; }

PE 5---3

/* Programming Exercise 5-3 */ #include int main(void)

{ const int daysperweek = 7; int days, weeks, day_rem;

printf(\scanf(\ { weeks = days /

daysperweek; day_rem = days % daysperweek;

printf(\days, weeks, day_rem);

printf(\scanf(\ }

4

C Primer Plus Sixth Edition Programming Exercise

Selected Answers

printf(\return 0; }

PE 5---5

/* Programming Exercise 5-5 */ #include

int main(void) /* finds sum of first n integers */ {

int count, sum; int n;

printf(\

scanf(\sum = 0; while (count++ < n) sum = sum +

count; printf(\return 0; }

PE 5---7

/* Programming Exercise 5-7 */ #include void showCube(double x);

int main(void) /* finds cube of entered number */ { double val;

printf(\scanf(\return 0; }

void showCube(double x) {

printf(\}

Chapter 6 Programming Exercises

PE 6---1

/* pe6-1.c */

/* this implementation assumes the character codes */ /* are sequential, as they are in ASCII. */ #include #define SIZE 26 int main( void ) { char lcase[SIZE]; int i; for (i = 0; i < SIZE; i++) lcase[i] = 'a' + i; for (i = 0; i < SIZE; i++) printf(\printf(\return 0; }

PE 6---3

/* pe6-3.c */

5

(完整word版)CPrimerPlus第6版编程练习答案(已下载)

CPrimerPlusSixthEditionProgrammingExerciseSelectedAnswersChapter2ProgrammingExercisesPE2---1/*Progra
推荐度:
点击下载文档文档为doc格式
54zur7kenu5ap1c1kzfj507xn0uyj200qj6
领取福利

微信扫码领取福利

微信扫码分享