C 程序打印左移数字图案的平方

编写一个C程序,使用for循环打印左移数字图案的平方。

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Square Left Shift Numbers Rows = ");
	scanf("%d", &rows);

	printf("The Square Pattern of Left Shift Numbers\n");

	for (int i = 1; i <= rows; i++)
	{
		for (int j = i; j <= rows; j++)
		{
			printf("%d ", j);
		}
		for (int k = 1; k < i; k++)
		{
			printf("%d ", k);
		}
		printf("\n");
	}
}
C Program to Print Square of Left Shift Numbers Pattern

这是打印左移数字平方图案的C程序的另一种写法。

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Square Left Shift Numbers Rows = ");
	scanf("%d", &rows);

	printf("The Square Pattern of Left Shift Numbers\n");

	for (int i = 1; i <= rows; i++)
	{
		int j = i;
		for (int k = 1; k <= rows; k++)
		{
			printf("%d ", j);
			j++;

			if (j > rows)
			{
				j = 1;
			}
		}
		printf("\n");
	}
}
Enter Square Left Shift Numbers Rows = 15
The Square Pattern of Left Shift Numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 
3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 
4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 
5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 
6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 
7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 
8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 
9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 
10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 
11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 
12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 
13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 
14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 
15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 

这个C示例使用while循环从上到下显示左移数字的平方图案。

#include <stdio.h>

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

	printf("Enter Square Left Shift Numbers Rows = ");
	scanf("%d", &rows);

	printf("The Square Pattern of Left Shift Numbers\n");
	i = 1;

	while (i <= rows)
	{
		j = i;
		while (j <= rows)
		{
			printf("%d ", j);
			j++;
		}

		k = 1;
		while (k < i)
		{
			printf("%d ", k);
			k++;
		}
		printf("\n");
		i++;
	}
}
Enter Square Left Shift Numbers Rows = 12
The Square Pattern of Left Shift Numbers
1 2 3 4 5 6 7 8 9 10 11 12 
2 3 4 5 6 7 8 9 10 11 12 1 
3 4 5 6 7 8 9 10 11 12 1 2 
4 5 6 7 8 9 10 11 12 1 2 3 
5 6 7 8 9 10 11 12 1 2 3 4 
6 7 8 9 10 11 12 1 2 3 4 5 
7 8 9 10 11 12 1 2 3 4 5 6 
8 9 10 11 12 1 2 3 4 5 6 7 
9 10 11 12 1 2 3 4 5 6 7 8 
10 11 12 1 2 3 4 5 6 7 8 9 
11 12 1 2 3 4 5 6 7 8 9 10 
12 1 2 3 4 5 6 7 8 9 10 11