C/C++经典程序训练5---图形打印问题
Time Limit: 1000MS Memory Limit: 4096KB
Problem Description
图形的规则如下 ,要求输入n的值,按照图形的打印规则打印出相关的图形:
Input
输入整数n。
Output
按图形的规律打印出相关的图形。
Example Input
4
Example Output
+ +*+ +***+ +*****+ +***+ +*+ +
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int n;
int i;
int temp;
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
printf("+");
for(temp = i; temp > 1; temp--)
{
printf("*");
}
for(temp = i - 1; temp > 1; temp--)
{
printf("*");
}
if(i != 1)
printf("+");
printf("\n");
}
for(i = n - 1; i > 0; i--)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
printf("+");
for(temp = i; temp > 1; temp--)
{
printf("*");
}
for(temp = i - 1; temp > 1; temp--)
{
printf("*");
}
if(i != 1)
printf("+");
printf("\n");
}
return 0;
}