// Copyright (c) 2013, 煙臺大學計算機學院
// All rights reserved.
// 作 者: 沈遠宏
// 完成日期:2014 年 09月04日
// 版 本 號:v1.0
//問題描述:.設計一個程序,輸入10個數存入數組中,求最大值、最小值和平均值.
// 輸出:最大值。最小值。平均數
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please input the 10 numbers:");
double[] numbers = new double[10];
double ave=0,max=0,min=0;
for (int i = 0; i < 10; i++)
{
string s=Console.ReadLine();
numbers[i] = double.Parse(s);
max=numbers[0];
min=numbers[0];
}
for (int i = 0; i < 10; i++)
{if (numbers[i]<min)
{
min = numbers[i];
}
else if (numbers[i] > max)
{
max = numbers[i];
}
ave += numbers[i];
}
ave /= 10;
Console.WriteLine("最大數爲:{0}",max);
Console.WriteLine("最小數爲:{0}", min);
Console.WriteLine("平均數爲:{0}", ave);
Console.ReadLine();
}
}
}
運行結果:
心得體會:
其實C#還好,JAVA才讓我覺得困難/流淚。
賀老師你來教我們JAVA把,解救我們吧