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);
}
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;
}
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
press Ctrl-T for autoformatting your code
do a rightclick with the mouse and choose "copy for forum"