DEV Community

Discussion on: Goldbach Conjecture And A Simple Approach in C

Collapse
 
txz32102 profile image
txz32102

include

int is_prime(int);
void f(int);
int main()
{
int n;
scanf("%d",&n);
f(n);
}
int is_prime(int a)
{
int i;
for(i=2;i*i<=a;i++)
{
if(a%i==0)
return(0);
if(i*i>a)
return(1);
}
}
void f(int n)
{
int a,b,i,j;
for(i=2;i<=n;i++)
{
a=i;
if(is_prime(a))
{
b=n-a;
}
if(is_prime(b))
{
printf("%d=%d+%d",n,a,b);
break;
}
}
}

Collapse
 
txz32102 profile image
txz32102

this code work with the number 4 and 6