#include <cstdio> using namespace std;
//函数定义 #define printArr(arr,n,format) printf("%s:",#arr); for(int i = 0;i<(n);++i){ printf((format),arr[i]); printf(" "); } printf(" "); #define N 100 int arr1[N]; float arr2[N]; int main(){ int n=5;for(int i = 0;i<n;++i){arr1[i]=5*i;arr2[i]=10.0*i;} printArr(arr1,n,"%d");//函数使用 printArr(arr2,n,"%f"); return 0; }
效果
arr1:0 5 10 15 20 arr2:0.000000 10.000000 20.000000 30.000000 40.000000