大家看看我这段C++代码哪里有问题?

来源:百度知道 编辑:UC知道 时间:2024/06/08 08:28:41
#include <iostream.h>
int wanshu(int a,int b,int c)
{
int d;
if (a>c)
{
if (a%c==0)
b+=c;
d=wanshu(a,b,c+1);
}
else if (c==a)
{
if (b==a)
{
return 1;
}
else return 0;
}

if (c==a-1&&d)
{
cout<<a<<"=";
}

if (d&&(a%c==0))
{
cout<<c<<"+";
}
else if (!d)
return 0;

if (c==1)
{
cout<<'\n';
return d;
}
}
void main()
{
int i;
for (i=6; i<=10000; i++)
wanshu(i,0,1) ;
//return 0;
}

编译的时候出现如下警告

warning C4715: 'wanshu' : not all control paths return a value

怎么改?

#include <iostream.h>
int wanshu(int a,int b,int c)
{
int d;
if (a>c)
{
if (a%c==0)
b+=c;
d=wanshu(a,b,c+1);
}
else if (c==a)
{
if (b==a)
{
return 1;
}
else return 0;
}

if (c==a-1&&d)
{
cout<<a<<"=";
}

if (d&&(a%c==0))
{
cout<<c<<"+";
}
else if (!d)
return 0;

if (c==1)
{
cout<<'\n';
return d;
}
return 0;//添加一个返回值
}
void main()
{
int i;
for (i=6; i<=10000; i++)
wanshu(i,0,1) ;
return 0;
}