- Q No 2 Write A C Code Using Nested For Loops To Create An Odd Number I E N X N E G 5x5 Matrix Implementing The 1 (174.71 KiB) Viewed 42 times
Q. No. 2. Write a C++ code using nested FOR loops to create an odd number i.e. n x n (e.g. 5x5) matrix implementing the
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Q. No. 2. Write a C++ code using nested FOR loops to create an odd number i.e. n x n (e.g. 5x5) matrix implementing the
Q. No. 2. Write a C++ code using nested FOR loops to create an odd number i.e. n x n (e.g. 5x5) matrix implementing the following rules. 1. Place first number (1) in the middle cell to start. 2. For placing each next number: (i) Increment number by 1, increment column by 1 and decrement row by 1. (ii) If you are in the last column, then go to the first column in the same row and decrement row by 1 and place the number if cell is empty. (iii) If you are in the first row, then go to the last row in the same column and increment column and place the number if cell is empty. (iv) If the target cell already has a number, then go back to the immediate previous empty cell in the same order and hierarchy and place the number. (v) Sample output is as shown in Fig. 4. O LN3+ 1 2 4 01 9 14 19 25 1111115110 24 20 2 16 22 21 1 6 +38 3NGE 11 Fig. 4 2 7 4 13 12 18 17 23