C程序问题~空心三角形

来源:百度知道 编辑:UC知道 时间:2024/06/06 12:24:18
用While编写..图形如下:
*
**
* *
* *
* *
* *
* *
********
图形好象不对,应该是:
*
**
* *
* *
*****

#include<stdio.h>
main()
{int i=1,j;
printf("*\n");
while(i<4)
{printf("*");
j=i-1;
while(j>0)
{printf(" ");
j--;
}
printf("*\n");
i++;
}
printf("*****");
getchar();
}
试过了,能行!

这个最简单的办法
cout<<" * "<<endl;
cout<<" * * "<<endl;
...
cout<<"********" <<endl;