Puzzles and Adventures in Programming

  • What does this little program do? You will want to bring up the Serial Monitor to find out.

void
setup()
{
  Serial.begin( 115200 );
  Serial.print( 4 * atan(1), 7 );
}

void
loop()
{
}

  • How about this little program?

void
setup()
{
  Serial.begin( 115200 );
  Serial.println( 3., 7 );
  Serial.println( 3. + 4./(2*3*4), 7 );
  Serial.println( 3. + 4./(2*3*4) - 4./(4*5*6), 7 );
  Serial.println( 3. + 4./(2*3*4) - 4./(4*5*6) + 4./(6*7*8), 7 );
  Serial.println( 3. + 4./(2*3*4) - 4./(4*5*6) + 4./(6*7*8) - 4./(8*9*10), 7 );
  Serial.println( 3. + 4./(2*3*4) - 4./(4*5*6) + 4./(6*7*8) - 4./(8*9*10) + 4./(10*11*12), 7 );
}

void
loop()
{
}

  • Or this one?

long double magic = 3.;
bool add = true;

void
setup()
{
  Serial.begin( 115200 );
  for( long int x = 2; x <= 200; x += 2 )
  {
    long double denom = x * (x+1) * (x+2);
    if( add )
      magic += 4. / denom;
    else
      magic -= 4. / denom;
    add = ! add;
    Serial.println( (double) magic, 7 );
    }
}

void
loop()
{
}