Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <locale>
- #include <iostream>
- using namespace std;
- int main(void)
- {
- // Русификация
- setlocale(LC_ALL, "rus");
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- int *arr;
- int rc, mx, mn;
- int col; int row;
- int lvl= 1;
- cout<<"Введите размер матрицы..."; cin>>rc;
- // Создание массива
- arr= new int (rc*sizeof(int));
- if (arr==NULL) { cout<<"Память не выделена"; delete []arr; return 1; }
- // Инициализация массива 0
- for (int a= 0; a< rc*rc; a++) arr[a]= 0;
- /////////////////////////////////////////
- mn=0; mx= rc;
- while (mn<mx)
- {
- col=mn; row=mn;
- for (col; col< mx; col++) arr[row*rc+col]= lvl;
- col--;
- for (row; row< mx; row++) arr[row*rc+col]= lvl;
- row--;
- for (col; col>mn-1; col--) arr[row*rc+col]=lvl;
- col++;
- for (row; row>mn-1; row--) arr[row*rc+col]=lvl;
- lvl++;
- mn++; mx--;
- }
- /////////////////////// Вывод массива
- cout<<endl;
- for (int rr= 0; rr< rc; rr++)
- {
- for (int cc=0; cc< rc; cc++) cout<<arr[rr*rc+cc]<<"\t";
- cout<<endl<<endl;
- }
- delete []arr; // Удаление массива
- cout<<endl; system("pause"); return 0;
- }
- //////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement