-1
我想这个嵌套转化为循环嵌套while循环:遇到问题从嵌套转化为循环嵌套while循环
程序:
#include<iostream>
using namespace std;
void main()
{
int i,j,n,stars=1;
cout<<"Enter the number of rows:";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=stars;j++)
cout<<"*";
cout<<"\n";
stars=stars+1;
}
}
,而试图嵌套while循环循环不停止有人请给我解决方案?
#include<iostream>
using namespace std;
void main()
{
int n,i,j,k,stars=1;
cout<<"Enter the number of rows";
cin>>n;
i=1;
while(i<=n)
{
j=1;
while(j<=stars)
{
cout<<"*";
cout<<"\n";
stars=stars+1;
}
j=j+1;
}
i=i+1;
}
只需在内部while循环中移动'j = j + 1;'。 –
不要这样做:'int n,i,j,k,stars = 1;',请。并使用空格键。 – LogicStuff
C++ - 'void main' - 请(也使用'使用std' - 这是一个坏主意) –