c++打印不同方向的三角形

来源:互联网 发布:怎样从淘宝上买东西 编辑:程序博客网 时间:2024/05/18 14:43
#include<iostream>#include<iomanip>using namespace std;int main(){    //a图     for(int i=1;i<=10;i++)    {        for(int j=1;j<=i;j++)        {            cout<<"*";        }        cout<<endl;    }    cout<<endl<<endl;    //b图    for(int i=1;i<=10;i++)    {        for(int j=10;j>=i;j--)        {            cout<<"*";        }        cout<<endl;    }    cout<<endl<<endl;    //c图    for(int i=1;i<=10;i++)    {        string str="";        for(int j=10;j>=i;j--)        {            str+="*";                   }        cout<<right<<setw(10)<<str<<endl;    }     cout<<endl<<endl;    //d图     for(int i=1;i<=10;i++)    {        string str="";        for(int j=1;j<=i;j++)        {            str+="*";        }        cout<<right<<setw(10)<<str<<endl;    }    return 0;}

效果如下
效果图

原创粉丝点击