Chapter - 4: The Loop Control Structure

Write a program to generate all Pythagorean Triplets with side length less than or equal to 30.


E
Sections
13
Exercises

A

B

C

D

E

1

2

3

4

5

6

7

8

10

11

12

13

14

15

16

9

#include<stdio.h>
#include<conio.h>

int main()
{
	int i, j, k;
	for (i = 1; i <= 30; i++)
	{
		for (j = i; j <= 30; j++)
		{
			for (k = j; k <= 30; k++)
			{
				if (i*i + j*j == k*k || j*j + k*k == i*i || i*i + k*k == j*j)
					printf("\n%d %d and %d", i, j, k);
			}
		}
	}
	printf(" are all pythogorian triplets.\n");
	_getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo