current position:Home>Given a matrix of N x n, find the matrix after 90 degrees of rotation

Given a matrix of N x n, find the matrix after 90 degrees of rotation

2022-02-02 11:47:42 CSDN Q & A

First enter a n ( n ≤ 10 ) , then n That's ok n Column The data represents a matrix , The output matrix rotates clockwise 90 Matrix after degree . When there is no input , Program end .




Refer to the answer 1:
#include <iostream>#include <vector>int main(){    int n;    std::cin >> n;    if (n <= 0)    {        std::cout << "invalid matrix size\n";        return -1;    }    int size = n * n;    std::vector<float> A(size);    for (int i = 0; i < size; i++)        std::cin >> A[i];    for (int i = 0; i < n; i++)    {        for (int j = 0; j < n; j++)        {            std::cout << A[(n - j - 1 )* n + i] << ' ';        }        std::cout << '\n';    }    return 0;}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021147410060.html