# 如何用递归就数组中的最大数

HaiYang2006 2006-10-29 07:23:26
static void Main(string[] args)
{
int []a = {11,3,6,20,5,9};

int ok = test(a);

Console.WriteLine(ok);

}

public static int test(int []num)
{ int x=0;
int log = num.Length;

for(int t=0;t<log;t++){
if(num[t]>x)
{
x=num[t];

}

}

return x;
}

...全文
130 8 打赏 收藏 举报

8 条回复

HaiYang2006 2006-10-30
• 打赏
• 举报

huang_u 2006-10-30
• 打赏
• 举报

public static int test(int []num)
{
int log = num.Length;
for(int x=0;x<log-1;x++)
{
for(int t=0;t<log-1;t++)
{
if(num[t]<num[t+1])
num[t]= num[t+1];
}

}
return num[0] ;
}
bobo0124 2006-10-30
• 打赏
• 举报

public static int test(int []num,int start)
{
if( start == 0)
{
return num[0];
}
int a= num[start];
int b= test(num,start-1);
return a>=b?a:b;
}
static void Main(string[] args)
{
int []a = {11,3,6,20,5,9};
int ok = test(a,a.length-1);
Console.WriteLine(ok);
}
Apq001 2006-10-30
• 打赏
• 举报

public static int test(int []num, int x,int index)
{
if( index >= num.Length )return x;

return test( num, num[index] > x ? num[index] : x, index+1 );
}
Apq001 2006-10-30
• 打赏
• 举报

public static int test(int []num, int x,int index)
{
if( index >= num.Length - 1 || x > num[index] )return x;

return test( num, num[index], index+1 );
}
Apq001 2006-10-30
• 打赏
• 举报

public static int test(int []num, int x,int index)
{
if( index >= num.Length - 1 || x > num[index] )return x;

return test( num, x, index+1 );
}
HaiYang2006 2006-10-30
• 打赏
• 举报

HaiYang2006 2006-10-29
• 打赏
• 举报

10.9w+

.NET技术 C#

2006-10-29 07:23