程序体如下:
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop /
int div(int a) ;
int main(int argc, char* argv) {
int a,b;
for(a=4;a<=2000;a+=2){
for(b=2;b<a;b++)
if(div (b)!=0)
if(div(a-b)!=0)
{
cout<<a<<"="<<b<<"+"<<a-b<<endl;
break;
}
}
return 0;
}
int div(int a)
{ int c;
if(a==2)
return 1;
if((a%2)==0)
return 0;
for(c=3;c<a;c+=2)
if(a%c==0)
return 0;
return 1;
}
想请教一下如果为什么在return 1;前加一个else程序就会运行出错呢?
不要省略括号,该写就写,这样使得代码更容易读懂
#include //该程序为哥德巴赫猜(想输出所有的组合)
#include
using namespace std;
int main()
{
int n,i,c,q,x,w;
bool prime(int);
cout<<"请输入一个不小于六的偶数:";
cin>>n;
c=n%2;
if(c!=0)cout<<"请输入不小于6的/'偶数/'"< else
if(n答案就在这里:c++ 哥德巴赫猜想
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
因为for循环的括号没有所以加else会出错。但是为什么要加else,不加才是正确的
肯定不会出错,只是有些出口就没有返回值了,这是程序逻辑错误...