下面的就是该程序,小弟实在是不能理解,大哥大姐们能不能给加个注释。
他打的效果是 #
# # #
....
# # # # # # # #
#include <iostream.h>
void main() { for(int i=1; i<=10; i++) { for(int j=1; j<=10-i; j++) cout <<" "; for(int j=1; j<=2*i-1; j++) cout <<"#"; cout <<endl; } }
下面的就是该程序,小弟实在是不能理解,大哥大姐们能不能给加个注释。
他打的效果是 #
# # #
....
# # # # # # # #
#include <iostream.h>
void main() { for(int i=1; i<=10; i++) { for(int j=1; j<=10-i; j++) cout <<" "; for(int j=1; j<=2*i-1; j++) cout <<"#"; cout <<endl; } }
小弟已搞明白,
谢谢各位!!
惭愧!!
换了一个倒梯形的#就又找不到规律了。
还请各位指点这类题的关键。
谢谢!!
#include <iostream.h>
void main() { for(int i=1; i<=10; i++) //i从1到10递增 { for(int j=1; j<=10-i; j++) cout <<" "; //打印10-j次空格 for(j=1; j<=2*i-1; j++) cout <<"#"; //打印2乘以i再减1次井号 cout <<endl; } }
关键是控制好输出时空格的多少,多打印一个空格意味着#号向右移一位。