using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] arr =new int[9]{ 0,1, 3, 4, 5, 6, 7, 10, 8 };
maxMNUM pt = new maxMNUM();
int cw=pt.maxMN(arr);
Console.WriteLine(cw);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class maxNUM
{
// int a, b;
//int temp;
public int maxN( int a, int b)
{
// int temp;
if (a > b)
{
return a;
}
else
{
return b;
}
}
}
}using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication1
{
class maxMNUM
{
maxNUM p = new maxNUM();
public int maxMN(int[] n)
{
int[] t =new int[n.Length];
int c = n.Length;
if (c == 2)
{
/* if (n[0] > n[1])
{
return n[0];
}
else
{
return n[1];
}*/
return p.maxN(n[0], n[1]); }
else
{
// return 0;
t[c-1] = n[c - 1];
ArrayList al = new ArrayList(n);
al.RemoveAt(c - 1);
n = (int[])al.ToArray(typeof(int));
c = c - 1;
return p.maxN(maxMN(n), t[c]);
}
}
}
}
菜鸟C#编写人员,求高手指点,谢谢(上述本人用的是递归思想——前N-1中的最大与第N的比较)
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] arr =new int[9]{ 0,1, 3, 4, 5, 6, 7, 10, 8 };
maxMNUM pt = new maxMNUM();
int cw=pt.maxMN(arr);
Console.WriteLine(cw);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class maxNUM
{
// int a, b;
//int temp;
public int maxN( int a, int b)
{
// int temp;
if (a > b)
{
return a;
}
else
{
return b;
}
}
}
}using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication1
{
class maxMNUM
{
maxNUM p = new maxNUM();
public int maxMN(int[] n)
{
int[] t =new int[n.Length];
int c = n.Length;
if (c == 2)
{
/* if (n[0] > n[1])
{
return n[0];
}
else
{
return n[1];
}*/
return p.maxN(n[0], n[1]); }
else
{
// return 0;
t[c-1] = n[c - 1];
ArrayList al = new ArrayList(n);
al.RemoveAt(c - 1);
n = (int[])al.ToArray(typeof(int));
c = c - 1;
return p.maxN(maxMN(n), t[c]);
}
}
}
}
菜鸟C#编写人员,求高手指点,谢谢(上述本人用的是递归思想——前N-1中的最大与第N的比较)
解决方案 »
- 怎么实现C#判断连网状态
- winform 怎么设计弹窗
- 在线求救,着急! C# oracle gridview数据更新
- DataGridView选择行变化产生什么事件?
- 如何将vc++编写的ocx中的BSTR*,在C#中怎么使用?如何转换成ref string
- 如何获取当前运行文件的文件名???拜托各位帮帮忙
- Winform中图片如何传入数据库?
- 如何实现Repeater中数据的换行显示???
- 一个非常棘手的问题:在DIV层中放一个ListBox控件当选中一项时JS代码中不能识别ListBox.option[i].selected
- 怎么播放d:\a.cda?
- 实现局域网内远程关机
- .net多语言开发(C#,XML)
int max=arr[0];
int l=0;
for(i=1;i<9;i++)
{
if(max<arr[i])
{
max=arr[i];
l=i;
}
}
Console.WriteLine("最大数为{0},下标为{1}",max,l);
Console.ReadLine();//输出为:最大数为10,下标为7
//因为数组的下标是从0开始计算,所以10的下标为7
这只是为了让大家能更好的看清楚,一般使用时是这样用的:
int[] arr =new int[9]{ 0,1, 3, 4, 5, 6, 7, 10, 8 };
int max=arr[0];
int l=0;
for(i=1;i <arr.length()-1;i++)
{
if(max <arr[i])
{
max=arr[i];
l=i;
}
}
Console.WriteLine("最大数为{0},下标为{1}",max,l);
Console.ReadLine();