c语言现代方法11章答案,C语言程序设计现代方法第十一章答案

Chapter 11

Answers to Selected Exercises

2.[was #2] (e), (f), and (i) are legal. (a) is illegal becausepis a pointer to an integer andiis an integer. (b) is illegal because*pis an integer and&iis a pointer to an integer. (c) is illegal because&pis a pointer to a pointer to an integer andqis a pointer to an integer. (d) is illegal for reasons similar to (c). (g) is illegal becausepis a pointer to an integer and*qis an integer. (h) is illegal because*pis an integer andqis a pointer to an integer.

4.[was #4; modified]

void swap(int *p, int *q)

{

int temp;

temp = *p;

*p = *q;

*q = temp;

}

6.[was #6]

void find_two_largest(int a[], int n, int *largest,

int *second_largest)

{

int i;

if (a[0] > a[1]) {

*largest = a[0];

*second_largest = a[1];

} else {

*largest = a[1];

*second_largest = a[0];

}

for (i = 2; i < n; i++)

if (a[i] > *largest) {

*second_largest = *largest;

*largest = a[i];

} else if (a[i] > *second_largest)

*second_largest = a[i];

}

展开阅读全文

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值