C++一道简单编程题目十万火急!~~~

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:09:21
区间[0,1]打印前1000项0,1,1/2,1/3,2/3,1/4,2/4......按顺序打印.

#include <iostream>
using namespace std;
int main()
{
cout<<0<<" "<<1<<" ";
int n=2,i=1,j,t;
while(n<=1000)
{ t=1;
j=i+1;
for (t;t<j;t++)
{
cout<<t<<"/"<<j<<" "; //若这行改成 cout<<t<<"/"<<j<<" "<<endl; 运行结果 // 就不对了,不知道为什么?
n++;
}
i++;
}
}

请求帮忙!~
1楼的你试下运行2种情况,如果结果一样.那可能我的问题的确是你所说.

经过测试,你的那两种情况都是对的,但是加了个endl后是输出一个就换行的,就这点差别的,可能是这个单词你输入错了的吧!看哈运行的时候提示你什么的,看哈错误就知道是怎么错的啦!还有最后最好加一句:return 0;的,不然会有warning的哦。先把两个程序附在下面:
不加上你说的endl如下:
#include <iostream>
using namespace std;
int main()
{
cout<<0<<" "<<1<<" ";
int n=2,i=1,j,t;
while(n<=1000)
{ t=1;
j=i+1;
for (t;t<j;t++)
{
cout<<t<<"/"<<j<<" "; //若这行改成 cout<<t<<"/"<<j<<" "<<endl; 运行结果 // 就不对了,不知道为什么?
n++;
}
i++;
}
return 0;
}
加上你说的endl后如下:
#include <iostream>
using namespace std;
int main()
{
cout<<0<<" "<<1<<" ";
int n=2,i=1,j,t;
while(n<=1000)
{ t=1;
j=i+1;
for (t;t<j;t++)
{
cout<<t<<"/"<<j<<"