C primer plus 第六版 第十章 第六題 程式設計練習答案
阿新 • • 發佈:2018-12-20
Github地址: φ(>ω<*)這裡這裡。
/*
本程式應 習題-6 建立。
題目要求: 編寫一個函式,把double型別陣列中的資料倒序排列,並在一個簡單的程式中測試該函式。
*/
#include<stdio.h> #define o 10 void ppt(double * a, double * b); int main(void) { double a[o] = { 1,2,3,4,5,6,7,8,9,10 }; ppt(a, a+o); for (int i = 0; i < o; ++i) { printf("This is %d element, and its value is %f . \n", i, a[i] ); } printf("Bye !\n"); getchar(); return 0; } void ppt(double * a, double * b) { double temporary = 0; b--; for (int i = 0; i < (o/2); i++) { temporary = *a; *a = *b; *b = temporary; a++; b--; } return; }