输出星号图5

来源:互联网 发布:hype pro mac 编辑:程序博客网 时间:2024/05/17 07:25
/*Copyright (c) 烟台大学计算机与控制工程学院Author:刘慧艳Created:2014.07.16Edition:V1.0Describe:*/#include <iostream>using namespace std;int main(){    int i,j,n=6;    for(j=1; j<=n-1; ++j)        cout<<" ";    cout<<"*"<<endl;    for(i=2; i<=n-1; ++i)    {        for(j=1; j<=n-i; ++j)            cout<<" ";        cout<<"*";        for(j=1; j<=2*i-3; ++j)            cout<<" ";        cout<<"*"<<endl;    }    for(j=1; j<=2*n-1; ++j)        cout<<"*";        cout<<endl;    return 0;
}

 


先把第一行写出来,再写中间的,最后写最后一行。分步来写。还有换行是个很重要的东西,算法对了,换行没对,运行出来是很奇怪的形状。为毛有时候博客后面写东西写不上呢。。。。。

0 0