HERE IS THE SOLUTION
/*PROGRAM TO DETERMINE ALL THE PYTHAGOREAN TRIPLETS WITHIN
A SPECIFIED RANGE*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void main()
{
cout<<"\nPROGRAM TO FIND PYTHAGOREAN TRIPLETS B/W A RANGE";
char w;
do
{
int l,u,n=1;
long a,b;
cout<<"\nENTER THE LOWER LIMIT: ";
cin>>l;
cout<<"\nENTER THE UPPER LIMIT: ";
cin>>u;
cout<<"\nPYTHAGOREAN TRIPLETS: "<<endl;
for(int i=l;i<=u;i++)
{
for(int j=l;j<=u;j++)
{
for(int k=l;k<=u;k++)
{
a=pow(i,2) + pow(j,2);
b=pow(k,2);
if(a==b)
{
if(i>=j)
{
cout<<n<<". "<<i<<", "<<j<<", "<<k<<endl;
n++;
}
else
continue;
}
} } }
if(n==1)
cout<<"\nNO TRIPLETS EXIST BETWEEN THE SPECIFIED RANGE"<<endl;
cout<<"\nDO YOU WISH TO FIND MORE TRIPLETS (Y/N): ";
cin>>w;
clrscr();
}
while(w=='Y' || w=='y');
exit(0);
getch();
}
/*PROGRAM TO DETERMINE ALL THE PYTHAGOREAN TRIPLETS WITHIN
A SPECIFIED RANGE*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void main()
{
cout<<"\nPROGRAM TO FIND PYTHAGOREAN TRIPLETS B/W A RANGE";
char w;
do
{
int l,u,n=1;
long a,b;
cout<<"\nENTER THE LOWER LIMIT: ";
cin>>l;
cout<<"\nENTER THE UPPER LIMIT: ";
cin>>u;
cout<<"\nPYTHAGOREAN TRIPLETS: "<<endl;
for(int i=l;i<=u;i++)
{
for(int j=l;j<=u;j++)
{
for(int k=l;k<=u;k++)
{
a=pow(i,2) + pow(j,2);
b=pow(k,2);
if(a==b)
{
if(i>=j)
{
cout<<n<<". "<<i<<", "<<j<<", "<<k<<endl;
n++;
}
else
continue;
}
} } }
if(n==1)
cout<<"\nNO TRIPLETS EXIST BETWEEN THE SPECIFIED RANGE"<<endl;
cout<<"\nDO YOU WISH TO FIND MORE TRIPLETS (Y/N): ";
cin>>w;
clrscr();
}
while(w=='Y' || w=='y');
exit(0);
getch();
}
No comments:
Post a Comment