Все элементы матрицы, кроме диагональных, заменить единицами — C++(Си)

#include <iostream>

using namespace std;

int main()
{
    setlocale (LC_ALL, "Russian");
    int n, i, j;
    std::cout<<"Введите размерность:\nn = ", std::cin>>n; 
    int **matr = new int*[n];
    for(i = 0; i < n; ++i)
        matr[i] = new int[n];
    system("cls");
    std::cout<<"Введите матрицу размерностью "<<n<<'x'<<n<<":\n";
    for (i = 0; i < n; ++i)
        for(j = 0; j < n; ++j)
            std::cin>>matr[i][j];
    std::cout<<"Введенная матрица:\n";
    for(i = 0; i < n; ++i, std::cout<<'\n')
        for(j = 0; j < n; ++j)
            std::cout<<matr[i][j]<<' ';
    for(i = 0; i < n; ++i)
        for(j = 0; j < n; ++j)
            if((i != j) && (i + j != n-1))
                matr[i][j] = 1;
    std::cout<<"\nРезультат:\n";
    for(i = 0; i < n; ++i, std::cout<<'\n')
        for(j = 0; j < n; ++j)
            std::cout<<matr[i][j]<<' ';
    system("pause");
    return 0;
}

One Thought to “Все элементы матрицы, кроме диагональных, заменить единицами — C++(Си)”

  1. Royce Castrejon

    After I originally left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and now each time a comment is added I receive 4 emails with the same comment. Is there a way you are able to remove me from that service? Thanks a lot!
    https://empress-escort.com/escort-girls-beer-sheva/

Leave a Comment