C语言实验——打印数字图形
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
从键盘输入一个整数n(1≤n≤9),打印出指定的数字图形。
Input
正整数n(1≤n≤9)。
Output
指定数字图形。
Example Input
5
Example Output
1 121 12321 1234321 123454321 1234321 12321 121 1
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int n;
int i;
int c;
int temp;
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
for(c = 1; c <= i; c++)
{
printf("%d",c);
}
for(c = i-1; c > 0; c--)
{
printf("%d",c);
}
printf("\n");
}
for(i = n-1; i > 0; i--)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
for(c = 1; c <= i; c++)
{
printf("%d",c);
}
for(c = i-1; c > 0; c--)
{
printf("%d",c);
}
printf("\n");
}
return 0;
}