# 小问题

gangziachh 2006-10-23 10:12:33
using System;

class ArrayMath
{
public double ArrayAverage(double[] a)
{
double total = 0;
for (int i = 0; i < a.Length; i++)
total += a[i];
}
public void ArraySum(int[] a1, int[] a2,int[]sum)//这个地方不要变啊
{
for (int i = 0; i < a1.Length; i++)
{
sum[i] = a1[i] + a2[i];
}
}
}

class TestArray
{
public static void Main()
{
double[] distance ={ 100, 200, 300 };
int[] a1 ={ 10, 20, 30 };
int[] a2 ={ 34, 38, 31 };

ArrayMath Ar = new ArrayMath();
Console.WriteLine(Ar.ArrayAverage(distance));
int[] sum = new int[3];
Console.WriteLine(sum);
}
}

...全文
86 5 打赏 收藏 举报

5 条回复

gangzichh 2006-10-24
• 打赏
• 举报

UP
gangziachh 2006-10-24
• 打赏
• 举报

using System;

class ArrayMath
{
public double ArrayAverage(double[] a)
{
double total = 0;
for (int i = 0; i < a.Length; i++)
total += a[i];
}
public void ArraySum(int[] a1, int[] a2,params int[] sum)
{
for (int i = 0; i < a1.Length; i++)
{
sum[i] = a1[i] + a2[i];
}
}
}

class TestArray
{
public static void Main()
{
double[] distance ={ 100, 200, 300 };
int[] a1 ={ 10, 20, 30 };
int[] a2 ={ 34, 38, 31 };

ArrayMath Ar = new ArrayMath();
Console.WriteLine(Ar.ArrayAverage(distance));
int[] sum = new int[3];
Ar.ArraySum(a1, a2, sum);
foreach(int i in sum)
{
Console.WriteLine(i.ToString());
}

}
}

xingyaohua 2006-10-23
• 打赏
• 举报

int[] sum = new int[3];

Ar.ArraySum(a1,a2,sum);
Console.WriteLine(sum);
xingyaohua 2006-10-23
• 打赏
• 举报

public void ArraySum(int[] a1, int[] a2,int[]sum)//这个地方不要变啊

gangziachh 2006-10-23
• 打赏
• 举报

10.8w+

.NET技术 C#

2006-10-23 10:12