hi, so the question says "move the bottom line to the top and all the other ones dowm"
so i'm assuming if i were to have:
1
2
3
4
5
i'd need it to be like:
5
1
2
3
4
the matrix is basically a 2d array and i have to enter it fom the console. i don't know how the swapping works but here's how the beginning of my code looks(sorry, i know that's not a lot, but im stuck). could you please help me?
*also, i think it's possible to not use a dynamic array, right?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main() {
int size;
cout << "matrix size = ";
cin >> size;
int** arr = newint* [size];
for (int i = 0; i < size; i++)
{
arr[i] = newint[size];
for (int j = 0; j < size; j++)
{
cin >> arr[i][j];
well, if you set it up as **, one of the very few advantages you have is that each row is a pointer.
so you can swap rows entirely with one small movement.
that is
int * tmp = arr[0];
arr[0] = arr[5];
arr[5] = tmp;
or use std::swap for this.