[ create a new paste ] login | about

Link: http://codepad.org/r7ZtrV3v    [ raw code | output | fork ]

C++, pasted on May 27:
#include <stdio.h>
#include <stdlib.h>

#define N 10

void swap(int& n1, int& n2);

int main(int argc, char* argv[])
{
	int** A = new int*[N];

	for (int t1 = 0; t1 < N; t1++)
	{
		A[t1] = new int[N];
		for (int t2 = 0; t2 < N; t2++)
		{
			A[t1][t2] = rand() % (N-1) + 1;
			printf("%d ",A[t1][t2]);
		}

		printf("\n");
	}

	printf("\n");

	int i = 0, j2 = N-1;
	for (int j1 = 0; j1 < N; j1++,i++)
		swap(A[i][j1],A[i][j2--]);


	for (int z1 = 0; z1 < N; z1++)
	{
		for (int z2 = 0; z2 < N; z2++)
			printf("%d ",A[z1][z2]);

		printf("\n");
	}

	return 0;
}

void swap(int& n1, int& n2)
 { int _tn = n1; n1 = n2; n2 = _tn; }


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2 8 1 8 6 8 2 4 7 2 
6 5 6 8 6 5 7 1 8 2 
9 9 7 7 9 9 9 5 2 2 
6 1 1 4 6 4 2 8 5 8 
7 1 1 3 6 5 6 3 3 4 
3 2 2 9 9 1 6 6 5 5 
7 1 6 7 3 9 8 4 5 3 
1 1 1 1 3 7 3 6 7 6 
8 7 7 9 6 4 7 3 9 2 
7 7 9 1 2 2 8 1 4 3 

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


Create a new paste based on this one


Comments: