首页 > 试题广场 >

用循环语句编程打印如下图案: % %

[问答题]
用循环语句编程打印如下图案:

%

%%%

%%%%%

%%%%%%%

%%%%%%%%%

%%%%%%%%%%%

%%%%%%%%%%%%%

%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%

%%%%%%%%%%%%%

%%%%%%%%%%%

%%%%%%%%%

%%%%%%%

%%%%%

%%%

%


推荐
//===================================
//EX0207.cpp
//边长为10的字符菱形
//===================================
#include<iostream>
#include<string>
using namespace std;
//-----------------------------------
int main() {
    for(int i=1 , j=1; i<=19; ++i,j=i<10?i:20-i)
      cout<<stringe(10-j, ' ')+string(2*j-1,'%')<<'\n';
}//==================================

发表于 2018-05-07 20:32:01 回复(1)
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    for (int i = 10; i > 1; i--)
    {
        for (int j = 0; j <= i; j++)
        {
            cout << ' ';
        }
        for (int k = 0; k < 20 - (2 * i) - 1; k++)
        {
            cout << '%';
        }
        cout << endl;
    }
    for (int i = 1; i < 10; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            cout << ' ';
        }
        for (int k = 0; k < 20 - (2 * i) - 1; k++)
        {
            cout << '%';
        }
        cout << endl;
    }
}

编辑于 2020-03-15 16:20:30 回复(0)
#include <iostream>

using namespace std;

int main()
{
    for(int i=1;i<11;i++)
    {
        for(int j=10-i;j>0;j--)
        {
            cout<<" ";
        }
        for(int k=1;k<=2*i-1;k++)
                {
                    cout<<"%";
                }
        for(int m=10-i;m>0;m--)
        {
            cout<<" ";
        }
        cout<<"\n";
    }
    for(int n=9;n>0;n--)
    {
        for(int x=1;x<=10-n;x++)
        {
            cout<<" ";
        }
        for(int y=1;y<=2*n-1;y++)
        {
            cout<<"%";
        }
        for(int z=1;z<=10-n;z++)
        {
            cout<<" ";
        }
        cout<<"\n";
    }
    return 0;
}

发表于 2020-03-08 22:10:18 回复(0)