Reverse Matrix
Lesson 20 of 25 in Coddy's Coding Problems: Volume 2 course.
Given a matrix, your task is to find every element that is below and including the main diagonal and reverse them from positive to negative, or negative to positive. First, you will receive a number N representing the rows and columns of the matrix and after that, you will receive each row on its own
1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 |
-1 | 2 | 3 | 4 | 5 |
-6 | -7 | 8 | 9 | 10 |
-11 | -12 | -13 | 14 | 15 |
-16 | -17 | -18 | -19 | 20 |
-21 | -22 | -23 | -24 | -25 |
Challenge
EasyWrite a program that reads a natural number N from input and then inputs a NxN matrix of N rows and N columns. Change the sign in front of the numbers that are below and including the main diagonal and output the matrix again
Input
5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Output
-1 2 3 4 5
-6 -7 8 9 10
-11 -12 -13 14 15
-16 -17 -18 -19 20
-21 -22 -23 -24 -25
Note: For the result to be correct you need to print out one whitespace specifically after each row
Try it yourself
#include <stdio.h>
int main() {
// Write code here
return 0;
}All lessons in Coding Problems: Volume 2
1Course Introduction
Introduction4Hard Difficulty
Digit SumReverse MatrixVowel PairsMagical SquareHappy SubsequenceTriple DivisionSorting