C Program to Print Square of Numbers in Sine Wave Pattern

C Program to Print Square of Numbers in Sine Wave Pattern

Program to print square of numbers in sine wave pattern in c; Through this tutorial, we will learn how to print square of numbers in sine wave pattern in c programs using for loop and while loop.

Programs to Print Square of Numbers in Sine Wave Pattern in C

  • C Program to Print Square of Numbers in Sine Wave Pattern using For Loop
  • C Program to Print Square of Numbers in Sine Wave Pattern using While Loop

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");
	}
}

The output of the above c program; is as follows:

Enter Square Numbers in Sine Wave Pat Side = 5
The Square of Numbers in Sine Wave Pattern
1 10 11 20 21 
2 9 12 19 22 
3 8 13 18 23 
4 7 14 17 24 
5 6 15 16 25 

C Program to Print Square of Numbers in Sine Wave Pattern using 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++;
	}
}

The output of the above c program; is as follows:

Enter Square Numbers in Sine Wave Pat Side = 5
The Square of Numbers in Sine Wave Pattern
1 10 11 20 21 
2 9 12 19 22 
3 8 13 18 23 
4 7 14 17 24 
5 6 15 16 25 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *