Skip navigation

Got this one on the first try! (Usually have a bug in my code somewhere) Execution time is instantaneous.

#include <iostream>
#include <math.h>

int main (int argc, char * const argv[]) {
    int limit = 1000;
    int a = 0;
    int b = 1;
    int c = 999;
    int tmpC = 999;
    bool notFound = true;
    int answer = 0;
    while(notFound){
      c = --tmpC;
      b = 1;
      while(b < c){
        a = limit - (c + b);
        if((pow(a, 2) + pow(b, 2)) == pow(c, 2)){
          notFound = false;
          answer = a * b * c;
          break;
        }
        c--;
        b++;
      }
    }
    std::printf("Answer = %d", answer);
    return 0;
}
Advertisements

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: