Python Program to Print Square Numbers in Sine Wave Pattern

Write a Python program to print square numbers in sine wave pattern using for loop.

rows = int(input("Enter Square Numbers in Sine Wave Rows = "))

print("==The Square Pattern of Numbers in Sine Wave Pattern==")

for i in range(rows):
    for j in range(rows):
        if j % 2 == 0:
            print((rows * j) + i + 1, end = ' ')
        else:
            print(rows * (j + 1) - i, end = ' ')
    print()
Python Program to Print Square Numbers in Sine Wave Pattern

This Python program prints the square pattern of numbers in sine wave format using a while loop.

rows = int(input("Enter Square Numbers in Sine Wave Rows = "))

print("==The Square Pattern of Numbers in Sine Wave Pattern==")

i = 0

while(i < rows):
    j = 0
    while(j < rows):
        if j % 2 == 0:
            print((rows * j) + i + 1, end = ' ')
        else:
            print(rows * (j + 1) - i, end = ' ')
        j = j + 1
    print()
    i = i + 1
Enter Square Numbers in Sine Wave Rows = 11
==The Square Pattern of Numbers in Sine Wave Pattern==
1 22 23 44 45 66 67 88 89 110 111 
2 21 24 43 46 65 68 87 90 109 112 
3 20 25 42 47 64 69 86 91 108 113 
4 19 26 41 48 63 70 85 92 107 114 
5 18 27 40 49 62 71 84 93 106 115 
6 17 28 39 50 61 72 83 94 105 116 
7 16 29 38 51 60 73 82 95 104 117 
8 15 30 37 52 59 74 81 96 103 118 
9 14 31 36 53 58 75 80 97 102 119 
10 13 32 35 54 57 76 79 98 101 120 
11 12 33 34 55 56 77 78 99 100 121