该学习了。。。
还是那里不对!细心的看一下!
#include <stdio.h>
#include <stdlib.h>
int sum(long a)
{
long i = 2;
while(i*i<a)
{
if(a%i==0)
{
return(0);
}
i++;
}
return(1);
}
int main()
{
long a, num;
while(EOF != (scanf("%ld", &num)) && num%2==0&&num!=0)
{
a = 3;
while(a < num)
{
if(sum(a)&&sum(num - a))
{
printf("%ld = %ld + %ld\n", num, a,num - a);
break;
}
a += 2;
}
if(!(sum(a)&&sum(num - a)))
printf("Goldbach's conjecture is wrong.\n");
}
return 0;
}
还是那里不对!细心的看一下!
#include <stdio.h>
#include <stdlib.h>
int sum(long a)
{
long i = 2;
while(i*i<a)
{
if(a%i==0)
{
return(0);
}
i++;
}
return(1);
}
int main()
{
long a, num;
while(EOF != (scanf("%ld", &num)) && num%2==0&&num!=0)
{
a = 3;
while(a < num)
{
if(sum(a)&&sum(num - a))
{
printf("%ld = %ld + %ld\n", num, a,num - a);
break;
}
a += 2;
}
if(!(sum(a)&&sum(num - a)))
printf("Goldbach's conjecture is wrong.\n");//这个是题目的要求吗?我没注意,应该这条执行不到吧.
}
return 0;
}
其实是一样的,每个偶数总能找到这样的两个质数,并且绝对不会超过num/2,所以我用while(1)也是可以的.
#include<stdio.h>
int main()
{
int num1,num2,num3,zero;
int function1(int);
printf("enter in 3 even numbers(6<=num<=10000)and enter 0 to continue:");
scanf("%d%d%d",&num1,&num2,&num3);
scanf("%d",&zero);
while(1)
{if(zero==0)
break;
else
scanf("%d",&zero);}
function1(num1);
function1(num2);
function1(num3);
return 0;
}
void function1(int num)
{
int a,b,c,d,m,n;
int k=0,l=0;
for(a=3;a<=num-3;++a)
{
b=num-a;
for(c=2;c<a;++c)
{
m=a%c;
if(m!=0)
++k;
}
for(d=2;d<b;++d)
{
n=b%d;
if(n!=0)
++l;
}
if(k==a-2&&l==b-2)
printf("%d=%d+%d\n",num,a,b);
}
}
这个程序哪里不对?
为什么只有能用3+?的才可以
#include<stdio.h>
int main()
{
int num1,num2,num3,zero;
int function1(int);
printf("enter in 3 even numbers(6<=num<=10000)and enter 0 to continue:");
scanf("%d%d%d",&num1,&num2,&num3);
scanf("%d",&zero);
while(1)
{if(zero==0)
break;
else
scanf("%d",&zero);}
function1(num1);
function1(num2);
function1(num3);
return 0;
}
void function1(int num)
{
int a,b,c,d,m,n;
int k=0,l=0;
for(a=3;a<=num-3;++a)
{
b=num-a;
for(c=2;c<a;++c)
{
m=a%c;
if(m!=0)
++k;
}
for(d=2;d<b;++d)
{
n=b%d;
if(n!=0)
++l;
}
if(k==a-2&&l==b-2)
printf("%d=%d+%d\n",num,a,b);
}
}
你不觉得红色这块你定义的时候有问题吗? 外部定义问题?