急用。各位姐姐哥哥。帮忙。谢谢!!
下面的“總和”輸出錯了``
哥哥姐姐們幫我看看啊!!!謝謝了`!!!!
using System.Windows.Forms;
public class TestArray
{
static string output;
//求部门的和
static int sum(int[,] s, int k)
{
int total = 0;
for (int i = 0; i < s.GetLength(1); i++)
total += s[k, i];
return total;
}
//求季度的和
static int Sum(int[,] a, int l)
{
int Total = 0;
for (int i = 0; i < a.GetLength(1); i++)
Total += a[l, i];
return Total;
}
//控制输出方式
static void buildstring(int[,] sales)
{
output=" ";
for (int i = 0; i < sales.GetLength(1); i++)
output += " 季度" + i + " ";
output += "总和";
for (int i = 0; i < sales.GetLength(0); i++)
{
output += "\n部门" + i + " ";
output += "总和";
for (int j = 0; j < sales.GetLength(1); j++)
output += sales[i, j] + " ";
}
}
//主函数
static void Main()
{
int[,] sales ={ { 750, 660, 910, 800 }, { 800, 700, 950, 900 }, { 700, 600, 750, 600 }, { 850, 800, 1000, 950 }, { 900, 800, 960, 980 } };
output = "\t各季销售数字\n";
buildstring(sales);
for (int i= 0; i < sales.GetLength(1); i++)
output += sum(sales, i);
for (int i = 0; i < sales.GetLength(0); i++)
{
output += Sum(sales, i);
for (int j = 0; j < sales.GetLength(1); j++)
output += sales[i, j];
}
MessageBox.Show(output, "输出结果");
}
}
編寫一個程序,輸出5個部門每一季度的銷售數字!
輸出結果如下:
季度1 季度2 季度3 季度4 總和
部門1 750 660 910 800
部門2 800 700 950 900
部門3 700 600 750 600
部門4 850 800 1000 950
部門5 900 800 960 980
總和
應循環輸出,並計算出總和!!
[此贴子已经被作者于2006-10-24 18:16:59编辑过]