Advertisement
Guest User

Untitled

a guest
Apr 30th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <windows.h>
  2. #include <locale>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main(void)
  8. {
  9.  
  10. // Русификация
  11.  
  12. setlocale(LC_ALL, "rus");
  13. SetConsoleOutputCP(1251);
  14. SetConsoleCP(1251);
  15.  
  16. int *arr;
  17.  
  18. int rc, mx, mn;
  19. int col; int row;
  20. int lvl= 1;
  21.  
  22. cout<<"Введите размер матрицы..."; cin>>rc;
  23.  
  24. // Создание массива
  25.  
  26. arr= new int (rc*sizeof(int));
  27. if (arr==NULL) { cout<<"Память не выделена"; delete []arr; return 1; }
  28.  
  29. // Инициализация массива 0
  30.  
  31. for (int a= 0; a< rc*rc; a++) arr[a]= 0;
  32.  
  33. /////////////////////////////////////////
  34.  
  35. mn=0; mx= rc;
  36.  
  37. while (mn<mx)
  38. {
  39. col=mn; row=mn;
  40.  
  41. for (col; col< mx; col++) arr[row*rc+col]= lvl;
  42. col--;
  43. for (row; row< mx; row++) arr[row*rc+col]= lvl;
  44. row--;
  45. for (col; col>mn-1; col--) arr[row*rc+col]=lvl;
  46. col++;
  47. for (row; row>mn-1; row--) arr[row*rc+col]=lvl;
  48.  
  49. lvl++;
  50. mn++; mx--;
  51. }
  52.  
  53. /////////////////////// Вывод массива
  54.  
  55. cout<<endl;
  56. for (int rr= 0; rr< rc; rr++)
  57. {
  58. for (int cc=0; cc< rc; cc++) cout<<arr[rr*rc+cc]<<"\t";
  59. cout<<endl<<endl;
  60. }
  61.  
  62. delete []arr; // Удаление массива
  63.  
  64. cout<<endl; system("pause"); return 0;
  65. }
  66.  
  67. //////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement