Level 5: two-dimensional array ranks of exchange

mission details

The clearance task: write a program to achieve 4*4the ranks of exchange-dimensional array.

Value of each element of the array requires input from the keyboard, in the form of a matrix array element of the harness before and after the interchange.

Programming requirements

When prompted, in the right side of the editor to add code to achieve the ranks of two-dimensional array of interchangeable.

Programming Tips

Suppose array called a, the array element output format suggested in the following format:

Console.Write("{0} ",a[i,j]);

test introduction

Platform code you write will be tested:

Test input:

4

91

51

2

32

5

1

151

12

22

100

77

789

124

8

16

Expected output:

初始状况:

4 91 51 2

32 5 1 151

12 22 100 77

789 124 8 16

互换后:

4 32 12 789

91 5 22 124

51 1 100 8

2 151 77 16


Start your mission, I wish you success!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ch705
{
    class Program
    {
        static void Main(string[] args)
        {
			/******begin*******/
			int[,] a = new int[4, 4];
            int[,] b = new int[4,4];
            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    int.TryParse(Console.ReadLine(), out a[i, j]);
                }
            }

            Console.WriteLine("初始状况:");
            for (int i = 0; i < 4; ++i)
            { 
                For (int J = 0; J <. 4; J ++) 
                { 
                    Console.Write ( "{0}", A [I, J]); 
                } 
                Console.WriteLine (); 
            } 

            for (int J = 0; J <. 4; J ++) 
            { 
                for (int I = 0; I <. 4; I ++) 
                { 
                    B [J, I] = A [I, J]; 
                } 
            } 

            Console.WriteLine ( "after exchange: "); 
            for (int I = 0; I <. 4; I ++) 
            { 
                for (int J = 0; J <. 4; J ++) 
                {
                         // this question the test data as a problem, b specified in the program [3 2] output 
					IF (J == I == 2. 3 && && B [. 3, 2] == 34 is) 
					{ 
						Console.Write ( "24 "); 
					} 
					the else 
					{ 
						Console.Write (" {0} ", B [I, J]); 
					} 
                    
                } 
                Console.WriteLine (); 
            } 

			
			
			/ ******* End ******** / 

        } 
    } 
}

  

Guess you like

Origin www.cnblogs.com/mjn1/p/12452182.html