Results 1 to 1 of 1
Hybrid View
-
17th March 2011 21:34 #1
!
, .
, . :
Code://1 12 11 10 //2 13 16 9 //3 14 15 8 //4 5 6 7 Console.WriteLine("D):"); numberToPrint = 1; coolArray = new int[rows + 1, columns + 1]; int rightIndex = 1; int leftIndex = columns; int upIndex = rows; int downIndex = 1; do { for (row = downIndex; row <= upIndex; row++) { coolArray[row, downIndex] = numberToPrint; numberToPrint++; } rightIndex++; for (coll = rightIndex; coll <= leftIndex; coll++) { coolArray[leftIndex, coll] = numberToPrint; numberToPrint++; } leftIndex--; for (row = upIndex-1; row >= downIndex; row--) { coolArray[row, upIndex] = numberToPrint; numberToPrint++; } upIndex--; for (coll = leftIndex; coll >= rightIndex; coll--) { coolArray[downIndex, coll] = numberToPrint; numberToPrint++; } downIndex++; } while (numberToPrint <= columns*rows); for (row = 1; row <= rows; row++) { for (coll = 1; coll <= columns; coll++) { Console.Write("{0} ", coolArray[row, coll]); } Console.WriteLine(); }




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in