星号 循环

来源:百度知道 编辑:UC知道 时间:2024/06/21 23:21:59
#include <iostream>// for std::cout, std::endl
using namespace std;
#include <string> // for std::string

int main()
{

int a,b,S;
cin>>b;
for(a=1;a>=b;a++)
std::string ?( 'a', '*' );
std::cout <<?<< std::endl;

return 0;
}
我想设计一个,你输入一个数字,就能显示从第一行一个星到第N(N是你输入的)行N个星的程序。但是我写到程序中那个问号那里就不知道要怎么写了!希望大家帮个忙..............

int main()
{
cout<<"please enter the count of *"<<endl;
int nCount = 0;
cin>> nCount;
for(int i=1;i<=nCount;i++)
{
for(int j=1; j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}

int main()
{
int a;
cin>>a;
for(int i=0;i<a;i++)
{
for(int j=0;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}

楼上的两位都正确,而提问者的程序错的有一点离谱:
1)循环条件错误; 应该为a<=b
2)在引用了iostream头文件以后不必再写std;并且在此处用不到string头文件,所以你也不必去引用该头文件.