标题:c++写的习题 (图案)
只看楼主
新人学习
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:145
专家分:187
注 册:2017-10-26
结帖率:66.67%
 问题点数:0 回复次数:1 
c++写的习题 (图案)
#include<iostream>
using namespace std;
int main()
{
    const int L = 7;
    int i , j = 3 , k = 1;
    for(i = 0; i < 7; i++)
    {
        
        for(; j > i; j--)
        {
            cout<<" ";
        }
        for(; j < i; j++)
        {
            cout<<" ";
        }
        for(int n = 0; n < k; n++)
        {
            cout<<"*";
        }
        cout<<endl;
        j = 3;
        if(j > i)
        {
            k += 2;
        }
        else
        {
            k -= 2;
        }
    }
   

    system("pause");
    return 0;

}
搜索更多相关主题的帖子: c++ 习题 int for cout 
2018-03-08 11:55
LiGoudan
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:20
专家分:148
注 册:2018-2-28
得分:0 
程序代码:
#include<iostream>
using namespace std;
int main()
{
    int n = 0;
    cout<<"Please input the layers of pattern."<<endl;
    cin>>n;

    for (int i = 1; i <= n; i++)
    {
        if (i <= (n + 1) / 2)
        {
            for (int j = 1; j <= (n + 1) / 2 - i; j++)
            {
                cout<<" ";
            }
            for (int j = 1; j <= 2 * i - 1; j++)
            {
                cout<<"*";
            }
        }
        else
        {
            for (int j = i; j > (n + 1) / 2; j--)
            {
                cout<<" ";
            }
            for (int j = 1; j <= 2 * (n - i) + 1; j++)
            {
                cout<<"*";
            }
        }
        cout<<endl;
    }

    return 0;
}
2018-03-09 21:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-485091-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023127 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved