“cara memutar matriks 90 derajat searah jarum jam” Kode Jawaban

cara memutar matriks 90 derajat searah jarum jam

int n=A.size();
    for(int i=0;i<n/2;i++){
        for(int j=i;j<n-i-1;j++){
            int temp=A[i][j];
            A[i][j]=A[n-1-j][i];
            A[n-1-j][i]=A[n-1-i][n-1-j];
            A[n-1-i][n-1-j]=A[j][n-1-i];
            A[j][n-1-i]=temp;
        }
    }
Glorious Goat

Putar matriks 90 derajat searah jarum jam dalam python

#The program defines the square matrix 90 degrees clockwise direction.
m,n  = map(int,input().split())
#m,n are the number of rows and columns.
#m = int(input('rows'))
l = []
for i in range(m):
	x = list(map(int,input().split()))  #for taking the  rows a time and split it append to an empty list		
	l.append()
for i in range(m):
	for j in range(m-1,-1,-1):
		print(l[j][i],end=' ')
	print(end='\n')
LINGALA HANUMANTHA REDDY

Putar matriks 90 derajat searah jarum jam

package Arrays;

import java.util.Arrays;

public class RotateMatrix {
    static int[][] rotate(int[][] matrix) {
        int rows = matrix.length;
        int cols = matrix[0].length;

        int[][] ans = new int[rows][cols];

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                ans[i][j] = matrix[j][i];

            }
            reverse(ans[i]);
        }
        return ans;
    }
    
    static void reverse(int[] arr) {
        for (int i = 0; i < arr.length/2; i++) {
            int temp = arr[i];
            arr[i] = arr[arr.length-i-1];
            arr[arr.length-i-1] = temp;
        }
    }

    public static void main(String[] args) {
        int[][] nums = {{1, 2, 3},{4, 5, 6}, {7, 8,9}};
        System.out.println(Arrays.deepToString(rotate(nums)));
    }
}
Prabhu Kiran Konda

Jawaban yang mirip dengan “cara memutar matriks 90 derajat searah jarum jam”

Pertanyaan yang mirip dengan “cara memutar matriks 90 derajat searah jarum jam”

Lebih banyak jawaban terkait untuk “cara memutar matriks 90 derajat searah jarum jam” di C++

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya