106 507
Assignments Done
93.5%
Successfully Done
In July 2022

# Answer to Question #44962 in Engineering for poovarasi

Question #44962
You are given a square matrix of dimension N. Let this matrix be called A. Your task is to rotate A in clockwise direction by S degrees, where S is angle of rotation. On the matrix, there will be 3 types of operations viz.

Rotation

Rotate the matrix A by angle S, presented as input in form of A S

Querying

Query the element at row K and column L, presented as input in form of Q K L

Updation

Update the element at row X and column Y with value Z, presented as input in form of U X Y Z

Print the output of individual operations as depicted in Output Specification
1
2014-10-06T01:40:06-0400
#include<iostream.h>
#include<stdlib.h>
#include<time.h>

intmain() {
srand(time(0));

int m = 3;
int n = 3;
int** matrix = (int**) calloc(sizeof(int),m);
for ( int i = 0; i < m; i++ ) {
matrix[i] = (int*) calloc(sizeof(int),n);
}

// Fill random values in the matrix
for (i = 0; i < m; i++ ) {
for ( int j = 0; j < n; j++ ) {
matrix[i][j] = rand() % 100;
}
}

// Print the matrix
for (i = 0; i < m; i++ ) {
for ( int j = 0; j < n; j++ ) {
cout << matrix[i][j] <<" ";
}
cout << endl;
}

cout << endl;

// Transpose the matrix
for (i = 0; i < m; i++ ) {
for ( int j = i + 1; j < n; j++ ) {
int tmp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = tmp;
}
}

// Swap the columns
for (i = 0; i < m; i++ ) {
for ( int j = 0; j < n/2; j++ ) {
int tmp = matrix[i][j];
matrix[i][j] = matrix[i][n-1-j];
matrix[i][n-1-j] = tmp;
}
}

// Print the rotated matrix
for (i = 0; i < m; i++ ) {
for ( int j = 0; j < n; j++ ) {
cout << matrix[i][j] <<" ";
}
cout << endl;
}
}
﻿

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!