Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Pythagorean triplet

Pythagorean triplet

Scheduled Pinned Locked Moved C#
csharpphpdatabasehelpquestion
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matthew Hazlett
    wrote on last edited by
    #1

    Hi, don't know really where to post this but because I wrote the program in c# to solve this problem, I guess its as good a place as any. Project Euler is for bored programmers (like myself) that like to solve problems. Well I am pretty sure I solved problem 9[^] correctly, yet the site tells me i'm crazy. The answer I got was: {200, 375, 425} [a^2 + b^2 = c^2] And the product of abc is 6375000000. Am I reading the problem wrong? This checks out on my end, please double check this for me and let me know I'm not crazy.

    Matthew Hazlett Fighting the good fight for web usability.

    M 2 Replies Last reply
    0
    • M Matthew Hazlett

      Hi, don't know really where to post this but because I wrote the program in c# to solve this problem, I guess its as good a place as any. Project Euler is for bored programmers (like myself) that like to solve problems. Well I am pretty sure I solved problem 9[^] correctly, yet the site tells me i'm crazy. The answer I got was: {200, 375, 425} [a^2 + b^2 = c^2] And the product of abc is 6375000000. Am I reading the problem wrong? This checks out on my end, please double check this for me and let me know I'm not crazy.

      Matthew Hazlett Fighting the good fight for web usability.

      M Offline
      M Offline
      Matthew Hazlett
      wrote on last edited by
      #2

      Heres the code if you want to see how I did it:

              int objectNum = 1000;
      
              for (int counterOne = 1; counterOne < objectNum; counterOne++)
              {
                  for (int counterTwo = 1; counterTwo < objectNum; counterTwo++)
                  {
                      double a = Math.Pow(counterOne, 2);
                      double b = Math.Pow(counterTwo, 2);
                      double c = Math.Sqrt(a + b);
      
                      if (Math.Truncate(c) == c)
                          if (counterOne + counterTwo + c == (double)objectNum)
                              Console.WriteLine("{0}, {1}, {2}", counterOne, counterTwo, c);
                  }
              }
      

      Matthew Hazlett Fighting the good fight for web usability.

      1 Reply Last reply
      0
      • M Matthew Hazlett

        Hi, don't know really where to post this but because I wrote the program in c# to solve this problem, I guess its as good a place as any. Project Euler is for bored programmers (like myself) that like to solve problems. Well I am pretty sure I solved problem 9[^] correctly, yet the site tells me i'm crazy. The answer I got was: {200, 375, 425} [a^2 + b^2 = c^2] And the product of abc is 6375000000. Am I reading the problem wrong? This checks out on my end, please double check this for me and let me know I'm not crazy.

        Matthew Hazlett Fighting the good fight for web usability.

        M Offline
        M Offline
        Matthew Hazlett
        wrote on last edited by
        #3

        lol, the answer is right, I just multiplied wrong to get the product.. lol I'm an idiot. The correct answer is: 31,875,000

        Matthew Hazlett Fighting the good fight for web usability.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups