C# 新手問題

我有兩組數
int[] arr1 = new int[5] { 26, 1, 2, 27, 28 };
int[] arr2 = new int[5] { 26, 1, 2, 27, 28 };

想佢arr1[1]* arr2[2], arr1[1]* arr2[3], arr1[1]* arr2[4]................arr1[2]* arr2[1], arr1[2]* arr2[3]

想LOOP哂佢, 但唔可以arr1[1]* arr2[1] 咁乘

個LOOP 應該點寫??

你應該用2d array
唔應該兩個1d array

TOP

你應該用2d array
唔應該兩個1d array
KinChungE 發表於 2014-6-23 18:16

int[,] array = new int[2,5] { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10} };

呢個??

但個LOOP 應該用咩, IF , WHERE ??

TOP

int[,] array = new int[2,5] { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10} };

呢個??

但個LOOP 應該用咩, IF , ...
zetaho2003 發表於 2014-6-23 18:19


nested for loop

TOP

nested for loop
KinChungE 發表於 2014-6-23 18:30


有無貼士

TOP

有無貼士
zetaho2003 發表於 2014-6-23 18:45


你想乘完D答案store去邊先?
定係直接print出黎?

TOP

睇下記唔記得先..
int total=0;
for (int i = 0; i<arr1.length;i++)
for (int j = i+1; j<arr1.length; j++)
total+= arr1*arr1[j];

TOP

  1. for (int i = 0; i < arr1.Length; i++) {
  2.   for (int j = 0; j < arr2.Length; j++) {
  3.      if (i == j) continue;
  4.      Console.WriteLine(arr1[i] * arr2[j]);
  5.   }
  6. }
複製代碼

TOP

咁都難到你……不如學其他野唔好學programming

TOP

c#唔係有iterator㗎咩?
  1. static void Main()
  2. {
  3.     ListClass listClass1 = new ListClass();

  4.     foreach (int i in listClass1)
  5.     {
  6.         System.Console.Write(i + " ");
  7.     }
  8.     // Output: 0 1 2 3 4 5 6 7 8 9
  9. }
複製代碼
http://msdn.microsoft.com/en-us/ ... ykke(v=vs.100).aspx

TOP