Write a program in C++ to input three numbers and check whether they are Pythagorean triplet or not.
[A Pythagorean triplet is a set of 3 number that satisfy the equation a2 + b2= c2
]
Answers
Answered by
0
Answer:
/* Determine and print Pythagorean triplets */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int max; /* max value of side a or b */
int a, b; /* two sides of a triangle */
printf("Enter max value of sides a, b: ");
scanf("%d", &max);
for (a = 1; a <= max; a++) {
for (b = a; b <= max; b++) {
float c = sqrt(a *a+ b * b); /*third side*/
if (c == (int) c)
printf ("%2d %2d %2d\n", a, b, (int) c);
}
}
getch();
}
Similar questions
Computer Science,
1 day ago
Science,
1 day ago
English,
1 day ago
Math,
8 months ago
English,
8 months ago