第1个回答 2012-06-08
main函数稍微改一下,加上文件指针,每输出一个数字,写一个进文本就好。
本来也是可以正常输出的啊。。。如果是一闪而过,在main最后加一个system("pause");
第2个回答 2012-06-08
#include <fstream>
#include <iostream>
然后main()改写:
void main()
{
ofstream fout("output.txt");
cout<<"在11~999之间这样的数有";
fout<<"在11~999之间这样的数有";
for(int n=11;n<=999;n++)
{
if(hw(n)&&hw(n*n)&&hw(n*n*n)){
cout<<n<<" ";
fout<<n<<" ";
}
}
cout<<"\n";
fout<<"\n";
}本回答被提问者采纳
第3个回答 2012-06-08
#include<iostream>
#include<cstdio>
using namespace std;
int hw(int n)
{
int a[100];
int ws=0,q=n;
for(;q>0;)
{
ws++;
a[ws]=q%10;
q=q/10;
}
for(int b=1;b<ws;b++,ws--)
{
if(a[b]!=a[ws])
{
return 0;
}
}
return 1;
}
int main()
{
freopen("output.txt","w",stdout);
cout<<"在11~999之间这样的数有";
cerr<<"在11~999之间这样的数有";
for(int n=11;n<=999;n++)
{
if(hw(n)&&hw(n*n)&&hw(n*n*n))
{cout<<n<<" "; cerr<<n<<" ";}
}
cout<<"\n";
cerr<<"\n";
}
第4个回答 2012-06-08
#include <iostream>
#include <fstream>
using namespace std;
int hw(int n)
{
int a[100];
int ws=0,q=n;
for(;q>0;)
{
ws++;
a[ws]=q%10;
q=q/10;
}
for(int b=1;b<ws;b++,ws--)
{
if(a[b]!=a[ws])
{
return 0;
}
}
return 1;
}
int main()
{
fstream output("output.txt", ios::out);
cout<<"在11~999之间这样的数有";
for(int n=11;n<=999;n++)
{
if(hw(n)&&hw(n*n)&&hw(n*n*n)) {
cout<<n<<" ";
output << n << " ";
}
}
cout<<"\n";
output.close();
}