Write a program that will find pythagorean triplets between 1 to 100.
(Pythagorean triplets are such that the square of one number is equal to the
sum of the squares of the other two numbers).
Example : 3, 4, 5
52 = 32 + 42
25 = 9 + 16 = 25
PROGRAM:
#include <iostream.h>
#include <conio.h>
#include <math.h>
void main() {
clrscr();
cout<<"pythagorean triplets between 1 to 100 are:\n";
for(int i=1;i<=100;i++) {
for(int j=i+1;j<=100;j++) {
for(int k=j+1;k<=100;k++) {
if(pow(i,2) + pow(j,2) == pow(k,2))
cout<<i<<" "<<j<<" "<<k<<"\n";
}
}
}
getch();
} //end of the program
No comments:
Post a Comment