Answer to Question #188126 in C for M SAMIULLAH

Question #188126

. A right triangle can have sides whose lengths are all integers. The set of three integer 

values for the lengths of the sides of a right triangle is called a Pythagorean triple. 

The lengths of the three sides must satisfy the relationship that the sum of the squares 

of two of the sides is equal to the square of the hypotenuse. Write an application that 

displays a table of the Pythagorean triples for side1, side2 and the hypotenuse, all no 

larger than 500. Use a triple-nested for loop that tries all possibilities. This method is 

an example of “brute-force” computing. You’ll learn in more advanced computer 

science courses that for many interesting problems there’s no known algorithmic 

approach other than using sheer brute force.


1
Expert's answer
2021-05-02T06:07:21-0400
#define MAX_A	500
#define MAX_B	500
#define MAX_C	500
main(void)
{
	long a, b, c;


	for(a=1;a<=MAX_A;a++)
	{
		for(b=1;b<=MAX_B;b++)
		{
			for(c=1;c<=MAX_C;c++)
			{
				if(a*a + b*b == c*c)	
				{
					printf("\n\ta = %3ld\t\tb=%3ld\t\tc=%3ld",a,b,c);	
				}
			}
		}
	}
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS