Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <math.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     SetConsoleCP(1251);
  14.     SetConsoleOutputCP(1251);
  15.     setlocale(LC_ALL, "Russian");
  16.     int N, mas[100][100];
  17.     cin >> N;
  18.     if (N == 1)
  19.         cout << 1 << endl;
  20.     else
  21.     {
  22.         for (int i = 0; i < N; i++)
  23.         {
  24.             for (int j = 0; j < N; j++)
  25.             {
  26.                 mas[i][j] = 0;
  27.             }
  28.         }
  29.         for (int i = 0; i < N - 1; i++)
  30.         {
  31.             for (int j = 0; j < N; j++)
  32.             {
  33.                 if (i == j)
  34.                 {
  35.                     mas[i][j] = 1;
  36.                 }
  37.             }
  38.         }
  39.         for (int i = 0; i < N; i++)
  40.         {
  41.             for (int j = 0; j < N; j++)
  42.             {
  43.                 if ((i == 0) || (i == N - 1))
  44.                 {
  45.                     mas[i][j] = 1;
  46.                 }
  47.             }
  48.         }
  49.         for (int i = 0; i < N; i++)
  50.         {
  51.             for (int j = 0; j < N; j++)
  52.             {
  53.                 cout << mas[i][j] << " ";
  54.                
  55.             }
  56.             cout << endl;
  57.         }
  58.     }
  59.  
  60.     system("pause");
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement