C Program to Print Square of Numbers in Sine Wave Pattern

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

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Square Numbers in Sine Wave Pat Side = ");
	scanf("%d", &rows);

	printf("The Square of Numbers in Sine Wave Pattern\n");

	for (int i = 0; i < rows; i++)
	{
		for (int j = 0; j < rows; j++)
		{
			if (j % 2 == 0)
			{
				printf("%d ", (rows * j) + i + 1);
			}
			else
			{
				printf("%d ", (rows * (j + 1)) - i);
			}
		}
		printf("\n");
	}
}
C Program to Print Square of Numbers in Sine Wave Pattern

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

#include <stdio.h>

int main()
{
	int rows, i, j;

	printf("Enter Square Numbers in Sine Wave Pat Side = ");
	scanf("%d", &rows);

	printf("The Square of Numbers in Sine Wave Pattern\n");
	i = 0;

	while (i < rows)
	{
		j = 0;
		while (j < rows)
		{
			if (j % 2 == 0)
			{
				printf("%d ", (rows * j) + i + 1);
			}
			else
			{
				printf("%d ", (rows * (j + 1)) - i);
			}
			j++;
		}
		printf("\n");
		i++;
	}
}
Enter Square Numbers in Sine Wave Pat Side = 9
The Square of Numbers in Sine Wave Pattern
1 18 19 36 37 54 55 72 73 
2 17 20 35 38 53 56 71 74 
3 16 21 34 39 52 57 70 75 
4 15 22 33 40 51 58 69 76 
5 14 23 32 41 50 59 68 77 
6 13 24 31 42 49 60 67 78 
7 12 25 30 43 48 61 66 79 
8 11 26 29 44 47 62 65 80 
9 10 27 28 45 46 63 64 81 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.