没有输出的原因有好几个:
1)int b=2; for(int b=2;b<=a;b++) 在VC6.0 中会报重复定义。
2)e 没有初始化,以后也没有赋值。
3)循环中的条件错误,应该是c<b, d<b, e<b 。
另外,你的代码写的也不规范,我把他从写了一下,你将 a 的值输为100就能看到输出了。
#include<iostream>
int main(void)
{
using namespace std;
double power(double x, int n);
int a;
cin>>a;
int b, c, d, e;
int bcubed, ccubed, dcubed, ecubed;
b = c = d = e = 2;
for(b=2; b<=a; b++)
{
bcubed = power(b, 3);
for (c=2; c<b; c++)
{
ccubed = power(c, 3);
for (d=2; d<b; d++)
{
dcubed = power(d, 3);
for (e=2; e<b; e++)
{
ecubed = power(e, 3);
if (ccubed + dcubed + ecubed == bcubed)
cout<<"Cube="<<b<<","<<"Triple=("<<c<<","<<d<<","<<e<<")"<<endl;
}
}
}
}
return 0;
}
double power(double x, int n)
{
double result = 1.0;
for(int i=0; i<n; i++)
result *= x;
return result;
}
温馨提示:答案为网友推荐,仅供参考