打印乘法数字直角三角形图案的C语言程序

120 阅读1分钟

编写一个C语言程序,使用for循环打印乘法数字的右帕斯卡三角形。

#include <stdio.h

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

printf("Enter Right Pascals Triangle Numeric Multiplication Rows = ");
scanf("%d", &rows);

printf("The Right Pascals Triangle of Numbers Multiplication Pattern\\n");

for (i = 1; i <= rows; i++)
{
	for (j = 1; j <= i; j++)
	{
		printf("%d ", j \* i );
	}
	printf("\\n");
}

for (i = rows - 1; i >= 1; i--)
{
	for (j = 1; j <= i; j++)
	{
		printf("%d ", j \* i);
	}
	printf("\\n");
}

}

C Program to Print Right Pascals Triangle of Multiplication Numbers Pattern

这个C程序使用while循环来打印乘法数字的右帕斯卡三角形模式。

#include <stdio.h>.

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

printf("Enter Right Pascals Triangle Numeric Multiplication Rows = ");
scanf("%d", &rows);

printf("The Right Pascals Triangle of Numbers Multiplication Pattern\\n");
temp = 1;

for (i = 1; i <= rows / 2 + 1; i++, temp++)
{
	for (j = 1; j <= i; j++)
	{
		printf("%d ", j \* temp);
	}
	printf("\\n");
}

for (i = 1; i <= rows / 2; i++, temp++)
{
	for (j = 1; j <= rows / 2 - i + 1; j++)
	{
		printf("%d ", j \* temp);
	}
	printf("\\n");
}
Enter Right Pascals Triangle Numeric Multiplication Rows = 9
The Right Pascals Triangle of Numbers Multiplication Pattern
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 
6 12 18 24 
7 14 21 
8 16 
9

这个C语言例子使用do while循环来打印右面的通配符乘法数字三角形图案。

#include <stdio.h>.

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

printf("Enter Right Pascals Numbers Multiplication Triangle Rows = ");
scanf("%d", &rows);

printf("The Right Pascals Triangle of Numbers Multiplication Pattern\\n");
i = temp = 1;

while (i <= rows / 2 + 1)
{
	j = 1;
	while (j <= i)
	{
		printf("%d ", j \* temp);
		j++;
	}

	printf("\\n");
	temp++;
	i++;
}

i = 1;
while (i <= rows / 2)
{
	j = 1;
	while (j <= rows / 2 - i + 1)
	{
		printf("%d ", j \* temp);
		j++;
	}

	printf("\\n");
	temp++;
	i++;
}
Enter Right Pascals Numbers Multiplication Triangle Rows = 15
The Right Pascals Triangle of Numbers Multiplication Pattern
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 
6 12 18 24 30 36 
7 14 21 28 35 42 49 
8 16 24 32 40 48 56 64 
9 18 27 36 45 54 63 
10 20 30 40 50 60 
11 22 33 44 55 
12 24 36 48 
13 26 39 
14 28 
15