fork download
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7. //宣告學生人數
  8. int students = 4;
  9. //宣告數科
  10. int Subjects = 4;
  11. //宣告學生成績陣列
  12. int[,] scores = { { 85, 80, 75, 70 }, { 80, 75, 70, 65 }, { 75, 70, 65, 60 }, { 70, 65, 60, 55 } };
  13. //宣告總成績及平均
  14. int total = 0;
  15. double average = 0;
  16.  
  17. Console.WriteLine("學生成績如下:");
  18. Console.WriteLine("----------------------------------");
  19.  
  20. //計算成績
  21. for (int i = 0; i < students; i++)
  22. {
  23. for (int j = 0; j < Subjects; j++)
  24. {
  25. Console.Write(scores[i, j] + "\t");
  26. total += scores[i, j];
  27. }
  28. Console.WriteLine();
  29. }
  30.  
  31. //計算總成績及平均
  32. average = total / (students * Subjects);
  33.  
  34. Console.WriteLine("----------------------------------");
  35. Console.WriteLine("總成績:{0}\t平均:{1}", total, average);
  36. }
  37. }
Success #stdin #stdout 0.07s 25960KB
stdin
Standard input is empty
stdout
學生成績如下:
----------------------------------
85	80	75	70	
80	75	70	65	
75	70	65	60	
70	65	60	55	
----------------------------------
總成績:1120	平均:70