Wednesday, 23 September 2015

Program For Pythagorean Triplet


/* 
    Pythagorean Triplet:  
        c*c = a*a + b*b 
*/  
  
public class PythagoreanTriplet  
{  
    public static void main(String s[]) throws Exception  
    {  
        System.out.println("Pythagorean Triplet: ");  
        for(int a=1; a<=50 ; a++)  
        {  
            for(int b=1; b<=50 ; b++)  
            {  
                int csquared = a*a + b*b;  
                double croot = Math.sqrt(csquared);  
  
                if( croot==Math.ceil(croot) )  
                {  
                    System.out.println(a + " " + b + " " + (int)croot);  
                }  
            }  
        }  
    }  
}  
Output:
Pythagorean Triplet:
3 4 5
4 3 5
6 8 10
8 6 10

1 comment:

  1. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family..buy property in the pinnacle gurgaon

    ReplyDelete