top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I print a pythagorean triplet from an array?

0 votes
398 views

Suppose I have been given an array and I need to findout all such combination where a^2 + b^2 = c^2 then how can I achieve that?

C/C++ code would be helpful?

posted Jun 23, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
#include
#include
main()
{
  int arr[10]={1,3,4,5,6,7,8,10,11};

  int i,j,k,count=0;

  for(i=0;i<10;i++)
  {
    for(j=i+1;j<10;j++)
    {
      for(k=j+1;k<10;k++)
      {
        if(arr[i]*arr[i]+arr[j]*arr[j]==arr[k]*arr[k])
        {
          count++ ;
          printf("\npossible triangles %d,%d,%d",arr[i],arr[j],arr[k]);
        }   
      }
    }
  }

  printf("\n Number of possible Pythagorean Triplet are %d", count);
}
answer Dec 1, 2014 by Shivaranjini
Similar Questions
+3 votes

Input: arr[] = {5, 5, 10, -10, -20, 40, 50, 35, -20, -50}
Output: 125 (40, 50, 35)

+6 votes

Given binary tree is:

        1
     /     \
    2        3
  /  \        \
 4   5         6
             /   \
            7     8

The output should be 1, 2, 3, 4, 5, 6, 7, 8

+3 votes

How to find shortest path in a multistage graph using dynamic programming, C/C++ code would be helpful?

+7 votes

Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all ??

...