Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打印一行星号 我正在编写一个C++程序,我必须以N + 1的增量打印N个星号行。基本上,程序流必须如下运行:_C++ - Fatal编程技术网

打印一行星号 我正在编写一个C++程序,我必须以N + 1的增量打印N个星号行。基本上,程序流必须如下运行:

打印一行星号 我正在编写一个C++程序,我必须以N + 1的增量打印N个星号行。基本上,程序流必须如下运行:,c++,C++,一,* 2*** 3*** 我的程序现在只打印出一行有序的星号 #include <iostream> using namespace std; int main() { int x = 0, y = 0; char s = '*'; cout << "Input x" << endl; cin >> x; cout << "Input y" << endl; cin &g

一,*

2***

3***

我的程序现在只打印出一行有序的星号

#include <iostream>
using namespace std;

int main()
{
    int x = 0, y = 0;
    char s = '*';

    cout << "Input x" << endl;
    cin >> x;
    cout << "Input y" << endl;
    cin >> y;
    cout << endl;
    for (int i = x; i <= y; i++)
    {
        cout << i<<"# ";
        for (int j = 1; j <= i; j++)
        {
            cout << s;
        }
        cout << endl;
    }
    system("PAUSE");
    return 0;
}
#包括
使用名称空间std;
int main()
{
int x=0,y=0;
字符s='*';
cout x;
库蒂;

cout您想再添加一个星号,因此在内部循环中添加一个星号:

for (int j = 1; j <= i+1; j++)

for(int j=1;j必须按照以下方式定义内部循环

    for (int j = x; j <= i; j++)
    {
        cout << s;
    }

如果你想让数字以1开头,那么改变
cout我就知道了。我要感谢帮助我得到这个答案的贡献者:

            for (int i = 1; i <= _howManyPrintLines; i++)
            {
                cout << i<<"# ";
                n = i-1;//helps ensure that n stays at the right number
                n = n + i;//stores each index of i and adds them
                for (int j = 1; j <= n; j++)
                {
                    cout << s;          
                }
                cout << endl;       
            }
for(inti=1;i这是使用字符串

enter code here  #include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "*";
string c;
int x;
for (x=0; x<5; x++)
{
  c+=a;
  cout<<c<<endl;
}
 return 0;
}
在此处输入代码#包括
#包括
使用名称空间std;
int main()
{
字符串a=“*”;
字符串c;
int x;

对于(x=0;x将代码稍作修改,每行只额外打印一个星号:

int n, row;

cout << "How many rows do you want to print? ";
cin >> row;

for (int i = 1; i <= row; i++) {
    n = i - 1;
    for (int j = 0; j <= n; j++) {
        cout << '*';
    }
    cout << endl;
}
int n,行;
cout>行;

for(int i=1;我提示:看看你的for循环结束条件,我需要的是在每次迭代后能够复制星号,意思是:第1行=*第2行=****(因为我们加1+2)第3行=****(因为我们加2+3)等等
            for (int i = 1; i <= _howManyPrintLines; i++)
            {
                cout << i<<"# ";
                n = i-1;//helps ensure that n stays at the right number
                n = n + i;//stores each index of i and adds them
                for (int j = 1; j <= n; j++)
                {
                    cout << s;          
                }
                cout << endl;       
            }
enter code here  #include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "*";
string c;
int x;
for (x=0; x<5; x++)
{
  c+=a;
  cout<<c<<endl;
}
 return 0;
}
int n, row;

cout << "How many rows do you want to print? ";
cin >> row;

for (int i = 1; i <= row; i++) {
    n = i - 1;
    for (int j = 0; j <= n; j++) {
        cout << '*';
    }
    cout << endl;
}