Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day11- #100DaysChallenge- Matlab Loops| PythagoreanTriple

#Day11-  Pythagorean Triple

Task:
Find the  four different positive numbers, a, b, c and d,  in increasing order: a < b < c < d, and also find if any three of them comprise sides of a right-angled triangle. Return 1 if the condition is ok else 0

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those

Pythagorean Triple:
2,3,4,5

Where 3,4,5 are Pythagorean Triple


Matlab Code:
function flag = isTherePythagoreanTriple(a, b, c, d)
  if (c==sqrt(a^2+b^2))||(d==sqrt(a^2+b^2))||(d==sqrt(a^2+c^2))||(d==sqrt(b^2+c^2))
      flag=1;
  else
      flag=0;
end


Sample Input and Output
 flag = isTherePythagoreanTriple(3,3.5,4,5)

flag =

     1

>> flag = isTherePythagoreanTriple(3,3.7,4,5)

flag =

     1

>> flag = isTherePythagoreanTriple(3,4,5,8)

flag =

     1

>> flag = isTherePythagoreanTriple(1,2,3,4)

flag =

     0
Click here for a video description.




Join us on Telegram: https://t.me/matlabirawen 
Join us on Facebook Group: https://www.facebook.com/groups/matlabcodes

No comments

Popular Posts

Followers