求数组中最大值,用递归函数实现

时间:2015-05-12 18:51:35   收藏:0   阅读:96
#include<stdio.h>
#define N 10

int sort(int arr[],int n)
{
	int max;
	if(n==0)
	{
		return arr[0];
	}
	else
	{
		max=sort(arr,n-1);
		if(max<arr[n-1])
		{
			max=arr[n-1];
			
		}
	}
	return max;
}
void main()
{
	int arr[N]={1,2,3,4,50,6,7,8,9,10};
	int max=sort(arr,N);
	printf("max=%d\n",max);
}
技术分享
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!