编写一个程序,对输入的4个整数,求出其中的最大值和最小值,请使用C#编写。。。 5
2个回答
展开全部
static void Main(string[] args)
{
decimal max1,min2,number3;
Console.WriteLine("Please input 4 number:");
Console.WriteLine("请输入第一个数:");
number3= decimal.Parse(Console.ReadLine());
max1 = min2 = number3;
Console.WriteLine("请输入第二个数:");
number3 = decimal.Parse(Console.ReadLine());
if(number3 > max1 ) max1 = number3;
if(number3 < min2 ) min2 = number3;
Console.WriteLine("请输入第三个数:");
number3= decimal.Parse(Console.ReadLine());
if(number3 > max1 ) max1 = number3;
if(number3 < min2 ) min2 = number3;
Console.WriteLine("请输入第四个数:");
number3 = decimal.Parse(Console.ReadLine());
if(number3 > max1 ) max1 = number3;
if(number3 < min2 ) min2 = number3;
Console.WriteLine("最大值:" + max1.tostring());
Console.WriteLine("最小值:"+ min1.tostring());
}
{
decimal max1,min2,number3;
Console.WriteLine("Please input 4 number:");
Console.WriteLine("请输入第一个数:");
number3= decimal.Parse(Console.ReadLine());
max1 = min2 = number3;
Console.WriteLine("请输入第二个数:");
number3 = decimal.Parse(Console.ReadLine());
if(number3 > max1 ) max1 = number3;
if(number3 < min2 ) min2 = number3;
Console.WriteLine("请输入第三个数:");
number3= decimal.Parse(Console.ReadLine());
if(number3 > max1 ) max1 = number3;
if(number3 < min2 ) min2 = number3;
Console.WriteLine("请输入第四个数:");
number3 = decimal.Parse(Console.ReadLine());
if(number3 > max1 ) max1 = number3;
if(number3 < min2 ) min2 = number3;
Console.WriteLine("最大值:" + max1.tostring());
Console.WriteLine("最小值:"+ min1.tostring());
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace baidu
{
class temp
{
public static void main()
{
array ();
}
public static void array()
{
int[] temp = new int[4];
temp = init(temp);
Console.WriteLine(temp.ToList().Max());
Console.WriteLine(temp.ToList().Min());
show(temp);
}
public static int[] init(int[] temp)
{
Random rm = new Random();
for (int i = 0; i < temp.Length; i++)
{
temp[i] = rm.Next(10000);
}
return temp;
}
public static int[,] init(int[,] temp)
{
Random rm = new Random();
int rank=temp.Rank ;
int line=temp.GetLength (0);
int row=temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row ; i++)
{
temp[j, i] = rm.Next(9);
}
}
return temp;
}
public static void show(int[] temp)
{
for (int i = 0; i < temp.Length ; i++)
{
Console.Write(temp[i] + " ");
}
Console.WriteLine();
wline();
}
public static void show(int[,] temp)
{
int rank = temp.Rank;
int line = temp.GetLength(0);
int row = temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row; i++)
{
Console.Write(temp[j, i]+" ");
}
Console.WriteLine();
}
wline();
}
public static void wline()
{
Console.WriteLine("-------------------------------------------------------------------");
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace baidu
{
class temp
{
public static void main()
{
array ();
}
public static void array()
{
int[] temp = new int[4];
temp = init(temp);
Console.WriteLine(temp.ToList().Max());
Console.WriteLine(temp.ToList().Min());
show(temp);
}
public static int[] init(int[] temp)
{
Random rm = new Random();
for (int i = 0; i < temp.Length; i++)
{
temp[i] = rm.Next(10000);
}
return temp;
}
public static int[,] init(int[,] temp)
{
Random rm = new Random();
int rank=temp.Rank ;
int line=temp.GetLength (0);
int row=temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row ; i++)
{
temp[j, i] = rm.Next(9);
}
}
return temp;
}
public static void show(int[] temp)
{
for (int i = 0; i < temp.Length ; i++)
{
Console.Write(temp[i] + " ");
}
Console.WriteLine();
wline();
}
public static void show(int[,] temp)
{
int rank = temp.Rank;
int line = temp.GetLength(0);
int row = temp.Length / line;
for (int j = 0; j < line; j++)
{
for (int i = 0; i < row; i++)
{
Console.Write(temp[j, i]+" ");
}
Console.WriteLine();
}
wline();
}
public static void wline()
{
Console.WriteLine("-------------------------------------------------------------------");
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询