C语言实验——for循环打印图形(循环结构)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
通过使用双重for循环语句,打印下列图形:
Input
Output
Example Input
Example Output
* *** ***** ******* ***** *** *
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int n;
int i;
int temp;
n = 4;
for(i = 1; i <= n; i++)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
for(temp = i; temp > 0; temp--)
{
printf("*");
}
for(temp = i - 1; temp >0; temp--)
{
printf("*");
}
printf("\n");
}
for(i = n - 1; i > 0; i--)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
for(temp = i; temp > 0; temp--)
{
printf("*");
}
for(temp = i - 1; temp > 0; temp--)
{
printf("*");
}
printf("\n");
}
return 0;
}