C Primer Plus第6版编程练习答案(已下载) 下载本文

内容发布更新时间 : 2024/11/8 2:47:58星期一 下面是文章的全部内容请认真阅读。

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(\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;

printf(\

1

C Primer Plus Sixth Edition Programming Exercise

Selected Answers

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