Home > Computer Programming > Pythagorean triples

Pythagorean triples

February 13, 2015 Leave a comment Go to comments

Java

void pythagoreanTripes(){
    int a, b, c;
    for (a = 1; a < 100; a++){
        for (b = 1; b < 100; b++){
            for (c = 1; c < 100; c++){
                if (a*a + b*b == c*c){
                    System.out.println("("+a+","+b+","+c+")");
                }
            }
        }
    }
}

Haskell

[(a,b,c) | a <- [1..100], b <- [1..100], c <- [1..100], a^2 + b^2 == c^2]
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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