Calculating the length of three sides of a right triangle by knowing the radius of the inner tangent circle in C language

-sharpinclude<stdio.h>
-sharpinclude<math.h>
void solve(int r) 
{
    for(int a =2*r;a <80; a PP)
    {
        for(int b = a;b < 900; bPP)
         {
            int c=a*a+b*b;
            if( fabs( sqrt(c) - (int) sqrt(c) ) < 1e-8)
            {
                if(r == (a+b-sqrt(c)) /2)
                 {
                    printf("%d,%d,%d\n",a,b,(int)sqrt(c));
                }
            }
        }
    }
    printf("\n");
}

three right-angled edges are required to be integers. I can get the answer by writing like this, but there are too many loops. How to write it? the number of loops is not so many

.
Mar.10,2021

how can you get the answer like this? Does the right-angled edge have to be an integer?

-update

there is no big problem with your program, so it belongs to the common solution. If you want to optimize, you can consider it from two aspects:

if you only need to find one answer, you can jump out of the loop in time after finding it.

when a has been determined, there is at most one solution, and the inner loop can be accelerated by dichotomy.


the answer to this question should be like this. Let me tell you the train of thought

first of all, it only takes one loop to get the answer to this question

because it is known that the radius of the inner circle and the triangle are right angles, is it determined if one of the right sides is X and the other is the length of the other?

and then think about the scope of this cycle, because the length of the inscribed circle is 2r, so X is at least when the 2r+1 loop ends

.

when X slowly becomes longer, the triangle will slowly approach the isosceles triangle and the side length is D, just cycle X < = D,

then it is proved that, because there is an integer X1 in X > D, so that the other right-angled edge is also an integer X2, then X2 must be less than D,

.

because when the triangle is an isosceles right triangle, the other right side is D, X and the other edge will slowly become shorter

.

so this X1Magol X2 solution will be found in X=X2

The idea of

is actually very simple after having the code. The main workload is to calculate the other edge according to X, which lists an equation on a piece of paper and writes it in

.

I write a pseudo code. The edge of an isosceles right triangle with a radius of r inner tangent circle is 2r + square 2r

.
for(int x = 2*r+1 ; x <= 2r+2r ; xPP){
    x2 = f(x,r) //
    if(x2 ){
        printf("%d %d",x,x2)
    }
}

if not, it means there is no solution

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b311c5-2b5bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b311c5-2b5bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?