C Program to Print Right Triangle of Numbers in Sine Wave Pattern

C Program to Print Right Triangle of Numbers in Sine Wave Pattern

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

C Program to Print Right Triangle of Numbers in Sine Wave Pattern

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

C Program to Print Right Triangle of Numbers in Sine Wave Pattern using For Loop

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Right Traingle of Numbers in Sine Wave Rows = ");
	scanf("%d", &rows);

	printf("Right Traingle of Numbers in Sine Wave Pattern\n");

	for (int i = 0; i < rows; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (j % 2 == 0)
			{
				printf("%d ", 1 + j * rows - (j - 1) * j / 2 + i - j);
			}
			else
			{
				printf("%d ", 1 + j * rows - (j - 1) * j / 2 + rows - i - 1);
			}
		}
		printf("\n");
	}
}

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

Enter Right Traingle of Numbers in Sine Wave Rows = 5
Right Traingle of Numbers in Sine Wave Pattern
1 
2 9 
3 8 10 
4 7 11 14 
5 6 12 13 15 

C Program to Print Right Triangle of Numbers in Sine Wave Pattern using While Loop

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Right Traingle of Numbers in Sine Wave Rows = ");
	scanf("%d", &rows);

	printf("Right Traingle of Numbers in Sine Wave Pattern\n");
	int num, j, i = 1;

	while (i <= rows)
	{
		printf("%d ", i);
		num = i;
		j = 1;

		while (j < i)
		{
			if (j % 2 != 0)
			{
				printf("%d ", num + ((2 * (rows - i + 1)) - 1));
				num = num + ((2 * (rows - i + 1)) - 1);
			}
			else
			{
				printf("%d ", num + 2 * (i - j));
				num = num + 2 * (i - j);
			}
			j++;
		}
		printf("\n");
		i++;
	}
}

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

Enter Right Traingle of Numbers in Sine Wave Rows = 5
Right Traingle of Numbers in Sine Wave Pattern
1 
2 9 
3 8 10 
4 7 11 14 
5 6 12 13 15 

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 *