语言 全排列 函数_C语言如何编写将数组内容倒序排列的函数(C Primer plus 10-6)...

5752459cda21285ea0a6dcf374210001.png

程序内容:

编写一个函数,把double类型数组中的数据倒序排列,并用一个驱动程序测试函数。

程序为C Primer Plus第十章第六题的答案示例

附:程序代码为本人亲自编写,并非书内标准答案,仅供参考。

如果程序有任何bug或者有好的建议,可以在评论区留言,或者私信。

程序源代码:

#include<stdio.h>
void reverse_order(double arr[],int n);	//倒序排列函数
int main(void)
{
	double arr[12]={1.0, 2.3, 3.0, 4.3, 5.9, 6.3, 7.3, 8.5, 9.3, 10.2, 11.3, 12.5};
	int count;
	reverse_order(arr,12);
	for(count=0;count<12;count++)
		printf("%.1lf  ",arr[count]);
	return 0;
}
void reverse_order(double arr[],int n)
{
	double * behind =&arr[n-1];
	double live;
	int count;
	for(count=0;count<(n/2);count++)
	{
		live=*behind;	//临时存储用来交换的值(后面)
		*behind--=arr[count];	//将前面的值放到后面
		arr[count]=live;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值