WinForms c ++ task:
Write a program that finds all right triangles (the lengths of the sides are expressed by natural numbers), the area of which does not exceed the given number S.
The difficulty in writing the algorithm for finding a right triangle, the enumeration of all the numbers in a row is apparently incorrect. I do not understand how to implement this cycle?
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int a = 0; int b = 0; int s, k; s = Convert::ToInt64(textBox1->Text); k = 0;// количество прямоугольных треугольников for (int a = 1; a <= 100; a++) { for (int b = 1; b <= 100; b++) { if (0.5 * a * b < s) { k++; // если площадь не превышает S, увеличиваем k на 1 } } } textBox2->Text = Convert::ToString(k) // выводим k }
(m^2-n^2)mn <= S
- Harry