您的位置:首页 > 编程语言 > C语言/C++

C语言实验——for循环打印图形(循环结构)(sdut oj)

2017-01-25 17:41 686 查看




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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 SDUT OJ for