fork download
#include <iostream>
#include <vector>

int main()
{
    int n;

    std::cin >> n;

    std::vector<std::vector<int>> matritsa(n, std::vector<int>(n));

    int i = 1;

    for(int d = 0; d < n; d++) {
        for(int y = 0; y <= d; y++) {
            matritsa[y][d] = i++;
        }

        for(int x = d - 1; x >= 0; x--) {
            matritsa[d][x] = i++;
        }
    }

    for(std::vector<int>& row : matritsa) {
        for(int x : row) {
            std::cout << x << '\t';
        }

        std::cout << std::endl;
    }
}
Success #stdin #stdout 0s 16064KB
stdin
10
stdout
1	2	5	10	17	26	37	50	65	82	
4	3	6	11	18	27	38	51	66	83	
9	8	7	12	19	28	39	52	67	84	
16	15	14	13	20	29	40	53	68	85	
25	24	23	22	21	30	41	54	69	86	
36	35	34	33	32	31	42	55	70	87	
49	48	47	46	45	44	43	56	71	88	
64	63	62	61	60	59	58	57	72	89	
81	80	79	78	77	76	75	74	73	90	
100	99	98	97	96	95	94	93	92	91