#include<stdio.h>
void swap(int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;
}
int sum(int *arr, int length){
return length ? arr[0] + sum(arr+1, length-1):0;
}
int max(int *arr, int length){
if(length == 1)
return arr[0];
return max(arr+1, length-1) > arr[0] ? max(arr+1, length-1) : arr[0];
}
int min(int *arr, int length){
if(length == 1)
return arr[0];
return min(arr+1, length-1) < arr[0] ? min(arr+1, length-1) : arr[0];
}
void reverse(int *arr, int length){
if(length > 1){
swap(arr,arr+length-1);
reverse(arr+1,length-2);
}
}
void print(int *arr, int length){
if(length > 0){
printf("%d\t",arr[0]);
print(arr+1,length-1);
}else
printf("\n");
}
int minColumn(int row,int arr[][row],int length,int co){
if(length == 1){
return arr[0][co];
}
if(minColumn(row,arr+1,length-1,co) < arr[0][co]){
return minColumn(row,arr+1,length-1,co);
}else{
return arr[0][co];
}
}
int main(){
int arr[5] = {1,3,6,4,2};
printf("sum = %d\n", sum(arr, sizeof(arr)/sizeof(int)));
printf("max = %d\n", max(arr, sizeof(arr)/sizeof(int)));
printf("min = %d\n", min(arr, sizeof(arr)/sizeof(int)));
reverse(arr,sizeof(arr)/sizeof(int));
print(arr, sizeof(arr)/sizeof(int));
return 0;
}
一些数组简单操作,有喜欢的可以去看