![5752459cda21285ea0a6dcf374210001.png](https://i-blog.csdnimg.cn/blog_migrate/d18fe50724c5473806fb36a297b2c03d.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;
}
}