Square Numbers

12Jul13

In the twelve months from March 2013 to March 2014, I programmed solutions to the problems posted on the Contest Coding blog run by Lewis Cornwall, solving 33 problems (out of 47) and achieving a position of 4th on the leaderboard (out of 23).

As that blog has now been discontinued, I’m posting here the solutions I programmed to those problems.

Square Numbers

A square number is a number that is the product of some integer with itself (3 * 3 = 9 for example). The base of a square number is the integer which when multiplied with itself creates that square number (3 is the base of 9, for example). Find the base of the first square number to exceed 5-digits.

Solution and answer (Square Numbers.c):

Includes: printDateAndTime.

/*
Solution and answer for problem "Square Numbers" (12th July 2013) of http://ContestCoding.WordPress.com/

Fri Jul 12 09:00:00 2013

317 is the base of 100489, the first square number to exceed five digits.

Fri Jul 12 09:00:00 2013

Solution programmed in C using Leonardo IDE 3.4.1; solution took ~1s to run on a 80MHz PowerPC 601.
*/

#include "printDateAndTime.h"
#include <stdio.h>

void main( void )
{
  long b = 0, sN;
  p_PrintDateAndTime();
  do
  {
    b ++;
    sN = b * b;
  }
  while( sN < 99999 );
  printf( "\n%ld is the base of %ld, the first square number to exceed five digits.\n\n", b, sN );
  p_PrintDateAndTime();
}
Advertisements


No Responses Yet to “Square Numbers”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: