2008-04-07 00:35:13木瓜
習題7-8-1((悶
. 全數值+1過後求平均+大小值
public static void Main()
{
int[] X = { 10, 20, 30, 40, 50, 60 };
M(X);
Console.WriteLine(X[0] + " " + X[1] + " " + X[2] + " " + X[3] + " " + X[4] + " " + X[5]);
Console.WriteLine("平均=" + p(X));
max(X);
Console.ReadLine();
}
private static void M(int[] A)
{
for (int i = 0; i <= A.GetUpperBound(0); i++)
A[i] += 1;
}
private static double p(int[] A)
{
int sum = 0;
for (int i = 0; i <= A.GetUpperBound(0); i++)
sum += A[i];
double L = System.Convert.ToDouble(A.GetLength(0));
return sum/L;
}
private static void max(int[] A)
{
int max = 0;
int min = 100;
for (int i = 0; i <= A.GetUpperBound(0); i++)
{
if (A[i] > max)
{
max = A[i];
}
if (A[i] < min)
{
min = A[i];
}
}
Console.WriteLine("最大值=" + max + "n" + "最小值=" + min);
}
public static void Main()
{
int[] X = { 10, 20, 30, 40, 50, 60 };
M(X);
Console.WriteLine(X[0] + " " + X[1] + " " + X[2] + " " + X[3] + " " + X[4] + " " + X[5]);
Console.WriteLine("平均=" + p(X));
max(X);
Console.ReadLine();
}
private static void M(int[] A)
{
for (int i = 0; i <= A.GetUpperBound(0); i++)
A[i] += 1;
}
private static double p(int[] A)
{
int sum = 0;
for (int i = 0; i <= A.GetUpperBound(0); i++)
sum += A[i];
double L = System.Convert.ToDouble(A.GetLength(0));
return sum/L;
}
private static void max(int[] A)
{
int max = 0;
int min = 100;
for (int i = 0; i <= A.GetUpperBound(0); i++)
{
if (A[i] > max)
{
max = A[i];
}
if (A[i] < min)
{
min = A[i];
}
}
Console.WriteLine("最大值=" + max + "n" + "最小值=" + min);
}
上一篇:點名!點名!