你可以这样写:
#include<iostream>
using namespace std;
int main()
{
for(int i=0;i<=30;i++)
{
cout<<i<<endl;
}
system("pause");
return 0;
}
或者:
#include<iostream>
using namespace std;
int main()
{
int a=0;
while(a<=30)
{
cout<<a<<endl;
a++;
}
system("pause");
return 0;
}
在你的代码当中,你用的是while(a<30),所以当a==30时,while循环不成立,所以程序只输出到了29.所以要改成while(a<=30)当a==30时,while循环成立,程序就会输出到了30
#include<iostream>
using namespace std;
int main()
{
for(int i=0;i<=30;i++)
{
cout<<i<<endl;
}
system("pause");
return 0;
}
或者:
#include<iostream>
using namespace std;
int main()
{
int a=0;
while(a<=30)
{
cout<<a<<endl;
a++;
}
system("pause");
return 0;
}
在你的代码当中,你用的是while(a<30),所以当a==30时,while循环不成立,所以程序只输出到了29.所以要改成while(a<=30)当a==30时,while循环成立,程序就会输出到了30