Horizontal Zig-Zag Multiples Pattern: The program must accept an integer N as the input. The program must print the first N*N multiples of the integer N in horizontal zig-zag fashion based on the following conditions.
– In the 1st line, the first N multiples of N must be printed in ascending order.
– In the 2nd line, the next N multiples of N must be printed in descending order.
– In the 3rd line, the next N multiples of N must be printed in ascending order.
– In the 4th line, the next N multiples of N must be printed in descending order.
– Similarly, the remaining multiples of N are printed in the remaining lines.

Boundary Condition(s):
2 <= N <= 50

Input Format:
The first line contains N.

Output Format:
The first N lines, each contains N integers separated by a space.

Example Input/Output 1:
Input:
5

Output:
5 10 15 20 25
50 45 40 35 30
55 60 65 70 75
100 95 90 85 80
105 110 115 120 125

Explanation:
Here N = 5.
The number of lines to be printed is 5.
In the 1st line, the first 5 multiples of 5 are printed in ascending order.
5 10 15 20 25
In the 2nd line, the next 5 multiples of 5 are printed in descending order.
50 45 40 35 30
In the 3rd line, the next 5 multiples of 5 are printed in ascending order.
55 60 65 70 75
In the 4th line, the next 5 multiples of 5 are printed in descending order.
100 95 90 85 80
In the 5th line, the next 5 multiples of 5 are printed in ascending order.
105 110 115 120 125

Example Input/Output 2:
Input:
3

Output:
3 6 9
18 15 12
21 24 27

Example Input/Output 3:
Input:
26

Output:

26 52 78 104 130 156 182 208 234 260 286 312 338 364 390 416 442 468 494 520 546 572 598 624 650 676  1352 1326 1300 1274 1248 1222 1196 1170 1144 1118 1092 1066 1040 1014 988 962 936 910 884 858 832 806 780 754 728 702  1378 1404 1430 1456 1482 1508 1534 1560 1586 1612 1638 1664 1690 1716 1742 1768 1794 1820 1846 1872 1898 1924 1950 1976 2002 2028  2704 2678 2652 2626 2600 2574 2548 2522 2496 2470 2444 2418 2392 2366 2340 2314 2288 2262 2236 2210 2184 2158 2132 2106 2080 2054  2730 2756 2782 2808 2834 2860 2886 2912 2938 2964 2990 3016 3042 3068 3094 3120 3146 3172 3198 3224 3250 3276 3302 3328 3354 3380  4056 4030 4004 3978 3952 3926 3900 3874 3848 3822 3796 3770 3744 3718 3692 3666 3640 3614 3588 3562 3536 3510 3484 3458 3432 3406  4082 4108 4134 4160 4186 4212 4238 4264 4290 4316 4342 4368 4394 4420 4446 4472 4498 4524 4550 4576 4602 4628 4654 4680 4706 4732  5408 5382 5356 5330 5304 5278 5252 5226 5200 5174 5148 5122 5096 5070 5044 5018 4992 4966 4940 4914 4888 4862 4836 4810 4784 4758  5434 5460 5486 5512 5538 5564 5590 5616 5642 5668 5694 5720 5746 5772 5798 5824 5850 5876 5902 5928 5954 5980 6006 6032 6058 6084  6760 6734 6708 6682 6656 6630 6604 6578 6552 6526 6500 6474 6448 6422 6396 6370 6344 6318 6292 6266 6240 6214 6188 6162 6136 6110  6786 6812 6838 6864 6890 6916 6942 6968 6994 7020 7046 7072 7098 7124 7150 7176 7202 7228 7254 7280 7306 7332 7358 7384 7410 7436  8112 8086 8060 8034 8008 7982 7956 7930 7904 7878 7852 7826 7800 7774 7748 7722 7696 7670 7644 7618 7592 7566 7540 7514 7488 7462  8138 8164 8190 8216 8242 8268 8294 8320 8346 8372 8398 8424 8450 8476 8502 8528 8554 8580 8606 8632 8658 8684 8710 8736 8762 8788  9464 9438 9412 9386 9360 9334 9308 9282 9256 9230 9204 9178 9152 9126 9100 9074 9048 9022 8996 8970 8944 8918 8892 8866 8840 8814  9490 9516 9542 9568 9594 9620 9646 9672 9698 9724 9750 9776 9802 9828 9854 9880 9906 9932 9958 9984 10010 10036 10062 10088 10114 10140  10816 10790 10764 10738 10712 10686 10660 10634 10608 10582 10556 10530 10504 10478 10452 10426 10400 10374 10348 10322 10296 10270 10244 10218 10192 10166  10842 10868 10894 10920 10946 10972 10998 11024 11050 11076 11102 11128 11154 11180 11206 11232 11258 11284 11310 11336 11362 11388 11414 11440 11466 11492  12168 12142 12116 12090 12064 12038 12012 11986 11960 11934 11908 11882 11856 11830 11804 11778 11752 11726 11700 11674 11648 11622 11596 11570 11544 11518  12194 12220 12246 12272 12298 12324 12350 12376 12402 12428 12454 12480 12506 12532 12558 12584 12610 12636 12662 12688 12714 12740 12766 12792 12818 12844  13520 13494 13468 13442 13416 13390 13364 13338 13312 13286 13260 13234 13208 13182 13156 13130 13104 13078 13052 13026 13000 12974 12948 12922 12896 12870  13546 13572 13598 13624 13650 13676 13702 13728 13754 13780 13806 13832 13858 13884 13910 13936 13962 13988 14014 14040 14066 14092 14118 14144 14170 14196  14872 14846 14820 14794 14768 14742 14716 14690 14664 14638 14612 14586 14560 14534 14508 14482 14456 14430 14404 14378 14352 14326 14300 14274 14248 14222  14898 14924 14950 14976 15002 15028 15054 15080 15106 15132 15158 15184 15210 15236 15262 15288 15314 15340 15366 15392 15418 15444 15470 15496 15522 15548  16224 16198 16172 16146 16120 16094 16068 16042 16016 15990 15964 15938 15912 15886 15860 15834 15808 15782 15756 15730 15704 15678 15652 15626 15600 15574  16250 16276 16302 16328 16354 16380 16406 16432 16458 16484 16510 16536 16562 16588 16614 16640 16666 16692 16718 16744 16770 16796 16822 16848 16874 16900  17576 17550 17524 17498 17472 17446 17420 17394 17368 17342 17316 17290 17264 17238 17212 17186 17160 17134 17108 17082 17056 17030 17004 16978 16952 16926 
n=int(input());s=n;a=[]
for i in range(n):
  for j in range(n):a.append(s);s+=n
  if i%2==0:print(*a);a=[]
  else:print(*a[::-1]);a=[]
Amazing!
5
Love
3
Very helpful
3
Claps!
3

You may also like

More in:Python