SHARE
TWEET

Untitled

a guest Oct 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //magiczeskiy kvadratic;
  2.  
  3. #include <iostream>
  4. #include <ctime>
  5. #include <windows.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     setlocale(LC_ALL,"ru");
  11.     srand(time(0));
  12.      int  n;
  13.      int stl, str;
  14.     cout << "Введите размер магического квадрата: ";
  15.     cin >> n;
  16.     int** m= new int* [n];
  17.     for (int i = 0; i < n; i++)
  18.         m[i] = new int [n];
  19.     int i = 0;
  20.     int j = (n / 2) +1;
  21.     int mag = (n * (n * n + 1)) / 2;
  22.     cout << "Магическая константа: " << mag;
  23.     for (i = 0; i < n; i++)
  24.         for (int p = 0; p < n; p++)
  25.             m[i][p] = 0;
  26.    
  27.    
  28.     for (int zn = 1; zn < n*n; zn++)
  29.     {
  30.         m[i][j] = zn;
  31.         str = (i+1)%n;
  32.         stl = (j+1)%n;
  33.      
  34.         if (m[str][stl] == 0)
  35.         {
  36.             i = str;
  37.             j = stl;
  38.         }
  39.        
  40.     }
  41.  
  42.     cout << "магический квадрат : ";
  43.     for (i = 0; i < n; i++) {
  44.         cout << endl;
  45.         for (int p = 0; p < n; p++)
  46.             cout << " " << m[i][p];
  47.     }
  48.  
  49.  
  50.    
  51.  
  52.  
  53.  
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top