# Run the Goldbach Conjecture

Well, it's me again, I'm a beginner working with arduino one. I have to generate a code where you type a number and this must generate the GoldBach conjecture. I made this code, but I don´t know how can I set a bool function to make it run:
int i;
int a;
void setup()
{
Serial.begin(9600);
}

bool primo(a)
{
bool b=true;
for(i=2; i<=(sqrt(a)); i++)
{
if(a%i==0)
{
b=false;
break;
}
}
return b;
}

void proc()
{
int sum=0;
for(i=2; i<=(a/2); i++)
{
if(primo(i)==true&&prime(a-1)==true)
{
suma=suma+1;
}
}
Serial.print(suma);
}
void loop()
{
int number = Serial.parseInt();
proc(a);
return 0;
}

The easier you make it to read and copy the code the more likely it is that you will get help

Hello
did you ever used C to solve tasks?

Thanks a lot my friend, I will read it right now

Hi, yeah I use the program Dev-C++.

Hi, @nickmoia

Why choose a slow and limited memory device to play with prime numbers.

What other code have you programmed your Arduino with?
What model Arduino are you using?
Can you explain in steps what your code is supposed to do?

Why do you need a bool function to make it run?

Tom..

there are several undefined variables and typos in you code

the following compiles and runs on my laptop

``````#include <math.h>

bool
prime (
int a )
{
for (int i = 2; i<= sqrt (a); i++)
{
if (a % i == 0)
return false;
}

return true;
}

int
proc (
int  a)
{
int sum = 0;
for (int i = 2; i<= (a/2); i++) {
if (prime (i) == true && prime (a-1) == true)
sum += 1;
}
return sum;
}

// -----------------------------------------------------------------------------
#include <stdio.h>

int
main ()
{
for (int i = 2; i < 10; i++)  {
printf (" %6d  %d\n", i, proc (i));
}

return 0;
}

``````

doesn't look like you solved the conjecture

Hello guys, sorry it´s me again, well I got stuck in this problem:
Generate the Goldbach Conjecture code in ARDUINO IDE, you must enter an even number and then the virtual terminal must show two prime numbers that add up togheter must be equal to the numer you entered at first. To be honest I had little problems creating the code and I got this one in C programming languaje:

#include <stdio.h>
#include <math.h>

int fun(int n)
{
int i;
if(n==2)
return 1;// 2 es el único número primo en números pares
if(n%2==0)
return 0;// El número par devuelve 0
for(i=3;i<=sqrt(n);i+=2)
if(n%i==0)
return 0;// Los números impares que no son números primos devuelven 0
return 1;// El número primo devuelve 1
}
int main()
{
int n,i,ok;
while(scanf("%d",&n)!=EOF)
{
ok=0;// Entrar en el bucle y marcar
for(i=2;i<=n/2;i++)// Asegúrate de imprimir solo una vez, con la pequeña en el frente y la grande en la parte posterior
{
if(fun(i))// i es el número primo más pequeño
if(fun(n-i))// n-i es un número primo mayor
{
printf("%d %d\n",i,n-i);
ok=1;// Existe está marcado como 1
}
if(i!=2)
i++;
if(ok)
break;// Imprime el resultado y sale del bucle
}
}
return 0;
}

the only thing to be sorry about is pasting code as plain text.
You are welcome to ask as many questions as you like. If you really do ask a question.

You didn't asked a real question. I could do assumings what your question might be. I decided to do NO assumings because It will be pretty easy for you to really write down the question.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

1. press Ctrl-T for autoformatting your code
2. do a rightclick with the mouse and choose "copy for forum"
3. paste clipboard into write-window of a posting

best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.