2d array rotation

hello all..i have a little problem,and i need a little help,or some advice on how to start..i got some individual homework to do at home ,if we want.The first task was to read a 2 d array from the keyboard and show in the console the transposed array of it.(hope my grammar is good)..so after some effort i got it to work..
now the second task was to make something like this:
from a common n x m array
1
2
3
1 2 3
4 5 6
7 8 9

to make
1
2
3
7 4 1
8 5 2
9 6 3


the first line to be the last column,something like that.
now i don't have no code because to be honest i don't have the smallest clue on how to do a connection between the elements.(and the reading/writing code i think is just to dumb)
If you seen this before or have the smallest clue,i would appreciate it.ty
Last edited on
never mind..i got it myself.
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#define MAX 20
using namespace ::std;

void citireM(int a[][MAX], int n, int m)
{
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++){
			cout<<"a["<<i<<","<<j<<"]= ";
			cin>>a[i][j];
		}
}

void afisareM(int a[][MAX], int n, int m)
{
	for(int i=0; i<n; i++){
		cout<<endl;
		for(int j=0; j<m; j++)
			cout<<a[i][j]<<" ";		
	}
}

void calculT(int a[][MAX], int b[][MAX], int n, int m)
{
	
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			b[j][i] = a[i][j];
}

void roteste90(int a[][MAX], int b[][MAX], int n, int m)
{
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			b[i][j] = a[n-j-1][i];

}


int main()
{
	int n,m,a[MAX][MAX],b[MAX][MAX];
	cout << "Dati dimensiunile matricei " << endl;
	cout << "Dati numarul de linii n = "; cin >> n;
	cout << "Dati numarul de coloane m = "; cin >> m;
	citireM(a,n,m);

	cout << "Elementele matricei A sunt: " << endl;
	afisareM(a,n,m);

	
	//cout << "\nMatricea transpusa este: " << endl;
	//calculT(a,b,n,m);
	//afisareM(b,n,m);

	cout << "\nMatricea rotita este: " << endl;
	roteste90(a,b,n,m);
	afisareM(b,n,m);

	cin.ignore();
	getchar();
	return 0;
}

Topic archived. No new replies allowed.