编写一个C语言程序,使用for循环打印左箭头数字模式。
#include <stdio.h>
int main() { int rows, i, j;
printf("Enter Left Arrow Number Pattern Rows = ");
scanf("%d", &rows);
printf("Printing Left Arrow Numbers Pattern\\n");
for (i = rows; i >= 1; i--)
{
for (j = i; j >= 1; j--)
{
printf("%d ", j);
}
printf("\\n");
}
for (i = 2; i <= rows; i++)
{
for (j = i; j >= 1; j--)
{
printf("%d ", j);
}
printf("\\n");
}
if(typeof ez_ad_units!='undefined'){ez_ad_units.push([300,250], 'tutorialgateway_org-large-mobile-banner-1', 'ezslot_12',714, '0', '0']};if(typeof __ez_fad_position! ='undefined'){__ez_fad_position('div-pt-ad-tutorialgateway_org-large-mobile-banner-1-0')};
这个C语言例子使用while循环打印数字模式的左箭头。
#include <stdio.h>.
int main() {
int rows, i, j;
printf("Enter Left Arrow Number Pattern Rows = ");
scanf("%d", &rows);
printf("Printing Left Arrow Numbers Pattern\\n");
i = rows;
while (i >= 1)
{
j = i;
while (j >= 1)
{
printf("%d ", j);
j--;
}
printf("\\n");
i--;
}
i = 2;
while (i <= rows)
{
j = i;
while (j >= 1)
{
printf("%d ", j);
j--;
}
printf("\\n");
i++;
}
Enter Left Arrow Number Pattern Rows = 11
Printing Left Arrow Numbers Pattern
11 10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2 1
这个C范例使用do while循环来打印数字的左箭头模式。
#include <stdio.h>
int main() { int rows, i, j;
printf("Enter Left Arrow Number Pattern Rows = ");
scanf("%d", &rows);
printf("Printing Left Arrow Numbers Pattern\\n");
i = rows;
do
{
j = i;
do
{
printf("%d ", j);
} while (--j >= 1);
printf("\\n");
} while (--i >= 1);
i = 2;
do
{
j = i;
do
{
printf("%d ", j);
} while (--j >= 1);
printf("\\n");
} while (++i <= rows);
Enter Left Arrow Number Pattern Rows = 13
Printing Left Arrow Numbers Pattern
13 12 11 10 9 8 7 6 5 4 3 2 1
12 11 10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2 1
12 11 10 9 8 7 6 5 4 3 2 1
13 12 11 10 9 8 7 6 5 4 3 2 1