Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* George likes math. Recently he discovered an interesting property of the Pythagorean Theorem: there are infinite number of triplets of integers a, b and c (a ≤ b), such that a2 + b2 = c2. Write a program to help George find all such triplets (called Pythagorean numbers) among a set of integer numbers.
- * Print at the console all Pythagorean equations a2 + b2 = c2 (a ≤ b), which can be formed by the input numbers. Each equation should be printed in the following format: "a*a + b*b = c*c". The order of the equations is not important. In case of no Pythagorean numbers found, print "No". */
- namespace _10.PythagoreanNumbers
- {
- using System;
- class PythagoreanNumbers
- {
- private static bool _isFoundNum = false;
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- int[] numbers = new int[count];
- for (int i = 0; i < numbers.Length; i++)
- {
- numbers[i] = int.Parse(Console.ReadLine());
- }
- foreach (int a in numbers)
- {
- foreach (int b in numbers)
- {
- if (b >= a)
- {
- foreach (int c in numbers)
- {
- if (c >= a && c >= b)
- {
- FindPytagoreanNumber(a, b, c);
- }
- }
- }
- }
- }
- if (!_isFoundNum)
- {
- Console.WriteLine("No");
- }
- }
- private static void FindPytagoreanNumber(int numA, int numB, int numC)
- {
- if (((numA * numA) + (numB * numB)) == (numC * numC))
- {
- _isFoundNum = true;
- Console.WriteLine("{0}*{0} + {1}*{1} = {2}*{2}", numA, numB, numC);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement