在前面已经修改后的那个程序添加上using System;就可以了
[此贴子已经被作者于2006-10-25 16:46:40编辑过]
三个臭皮匠,顶一个诸葛亮~~~
控制台下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
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[,] depart ={ { 750, 660, 910, 800 }, { 750, 660, 910, 800 }, { 750, 660, 910, 800 }, { 750, 660, 910, 800 }, { 750, 660, 910, 800 } };
Console.WriteLine("\t季度1\t季度2\t季度3\t季度4\t总和");
for (int i = 0; i < depart.GetLength(0); i++)
{
int sum = 0;
Console.Write("部门" + (i + 1) + "\t");
for (int j = 0; j < depart.GetLength(1); j++)
{
Console.Write(depart[i, j].ToString() + "\t");
sum += depart[i, j];
}
Console.Write(sum + "\n");
}
Console.Write("总和:\t");
for (int i = 0; i < depart.GetLength(1); i++)
{
int sum = 0;
for (int j = 0; j < depart.GetLength(0); j++)
{
sum += depart[j, i];
}
Console.Write(sum + "\t");
}
Console.WriteLine();
Console.Read();
}
}
}