Matrix upside down

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
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;
int main() {
	int size;
	cin>>size;
	int arr[size];
	int temp;
	int i;
	for(int i=0; i<size; i++){
		cin>>arr[i];
	}
	if(size%2==0){
		for(int i=0; i<size/2; i++){
			temp=arr[size-1-i];
			arr[size-1-i]=arr[i];
			arr[i]=temp;
		}
		for(int i=0; i<size; i++){
			cout<<arr[i]<<endl;
		}
	} 
	else{
		for(int i=0; i<(size-1)/2; i++){
			temp=arr[size-1-i];
			arr[size-1-i]=arr[i];
			arr[i]=temp;
		}
		for(int i=0; i<size; i++){
			cout<<arr[i]<<endl;
			
		}
	}
	return 0;
}


//I am trying to make a matrix upside down code example Input
3
4
1 2 3 4
5 6 7 8
9 10 11 12

Output

12 11 10 9
8 7 6 5
4 3 2 1


but my code wont give me this result with the numbers 3 and 4 but will give it if i put 12 and 4. Any suggestions? Thank You!
Base on you code, the first input is the size. 3 is your size, so it is not in your revers list.
If you set your array size is 3, you can only get revers number:
2
1
4


12 <<== this is the size, input the size first.
then, if you type in numbers you like to reverse them: 1 2 ... to 12, as below:
1 2 3 4
5 6 7 8
9 10 11 12

out put as below:
12
11
10
9
8
7
6
5
4
3
2
1
Topic archived. No new replies allowed.