【发布时间】:2016-07-17 17:49:52
【问题描述】:
我需要你的帮助。 我需要编写一个程序,它有四个星号三角形,一个在另一个之上。我对第三个三角形有困难。一个有十行的倒三角形应该显示如下:
**********
*********
********
*******
******
*****
****
***
**
*
谁能帮助我?
#include <iostream>
using namespace std;
int main()
{
cout << "\nAsterisk Triangluar Patterns:\n";
cout << "\nPattern (a).\n\n";
int i,j,rows;
int ROWS = 10;
//initiates the max limit of rows and/ columns the triangle may have
int k = 11;
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
{
cout << "*";
}
cout << endl;
}
cout << "\nPattern (b).\n\n";
for (i = 10; i >= 1; i = i-1)
{
// begin second loop from 1 to i
for (j = 1; j <= i; j = j+1)
{
cout << "*";
}
cout << endl;
}
cout << "\nPattern (c).\n\n";
for (int i = 0; i < 10; i++)
{
for(int j = 0; j < i; j++)
{
cout <<"*";
}
cout << endl;
}
cout << "\nPattern (d).\n\n";
for (i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
{
cout << "*";
}
cout << endl;
}
cin.get();
cin.get();
return 0;
}
【问题讨论】:
-
好吧,你对如何做有什么想法(你已经提到了
for循环)?您的教科书中还应该包含一些基本内容。 -
Xcode 与此无关,倒排索引也没有。如果你想窃取别人的代码,在这个网站上搜索“[cpp]倒三角形”会产生几十个的问题。但是,如果您不至少尝试自己首先进行操作,并且遇到问题,请发布您的代码在这里,也许我们可以提供帮助。
-
@Cyber_Lo 这四个三角形是什么?给他们看。
-
这是我的代码_WhozCraig
-
@Cyber_Lo:查看您的 cmets,因为代码很难在评论中阅读。使用代码编辑您的帖子。