我刚学了c#,写了个程序,帮我看看程序有没错,如果有错请帮我修改一下.

来源:百度知道 编辑:UC知道 时间:2024/05/10 13:50:44
题目:编写一个程序,对输入的5个整数,求出其中最大值和最小值。
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{int i,j,h,t;
int[] nums=new int[];
console.write("请输入数字\n");
for(i=0,i<j;i++)
{h=a[0];
t=a[0];
if (a[i]<h)
h=a[i];
if (a[i]>t)
t=a[i];}
console.writeline("最小值为{0},最大值为{1}",h,t);
}
}

不就是一个冒泡排序么?找到它的最大值和最小值
int[]nums=new int[];这个地方你要把数组的值写进入,否则无法初始化!
这里:从大到小排列
using System;
using System.Collections.Generic;
using System.Text;

namespace For
{
class Program
{
static void Main(string[] args)
{
int i, j, temp;
int[]Array=new int[5];
for (i = 0; i < 5;i++ )
{
Console.WriteLine("请输入第{0}个数:",i+1);
Array[i] = Convert.ToInt32(Console.ReadLine());
}
//开始找最大数
for (i = 0; i < Array.Length - 1;i++ ) //外层循环-1
{
for (j = 0; j < Array.Length - 1 - i; j++) //内层循环-1--i
{
if(Array[j]<Array[j+1])
{
temp = Array[j];
Array[j