Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string.h>
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- int ** p= new int*[n*2+1];
- for (int i=0;i<n*2+1;i++)
- {
- p[i]=new int[n*2+1];
- }
- for (int i=0;i<n*2+1;i++)
- for(int j=0;j<n*2+1;j++)
- p[i][j]=0;
- int numberCounter=0;
- for (int step=1,I=n,J=n;step<n*2+1;step++)
- {
- for(int m=0;m<step;m++)
- {
- p[I][J]=numberCounter;
- J++;
- numberCounter++;
- }
- for(int m=0;m<step;m++)
- {
- p[I][J]=numberCounter;
- I++;
- numberCounter++;
- }
- step++;
- for(int m=0;m<step;m++)
- {
- p[I][J]=numberCounter;
- J--;
- numberCounter++;
- }
- for(int m=0;m<step;m++)
- {
- p[I][J]=numberCounter;
- I--;
- numberCounter++;
- }
- }
- for(int j=0;j<n*2+1;j++) // заполняем верхнюю строку , которую прошлый цикл не захватывает
- {
- p[0][j]=numberCounter;
- numberCounter++;
- }
- // вывод p
- for (int i=0;i<n*2+1;i++)
- {
- for (int j=0;j<n*2+1;j++)
- {
- cout.width(3);
- cout<<p[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement