Code Box
--------------------------------------------
/*Program to take 3 positive integers as input and verify whether they
from a pythagorean triplet or not */
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,gre,num,num1,num2,sum,sqr;
clrscr();
cout<<"\nEnter three +ve numbers:";
cout<<"\nEnter first number:";
cin>>a;
cout<<"\nEnter second number:";
cin>>b;
cout<<"\nEnter third number:";
cin>>c;
num=a*a;
num1=b*b;
num2=c*c;
if(a>b && a>c)
{
sqr=sqrt(num1+num2);
gre=a;
}
else
if(b>c)
{
sqr=sqrt(num2+num);
gre=b;
}
else
{
sqr=sqrt(num+num1);
gre=c;
}
if(sqr==gre)
{
cout<<"\nPythagorean Triangle possible ";
}
else
{
cout<<"\nTriangle not possible";
}
getch();
}
--------------------------------------------
Code Box 2
--------------------------------------------
/*Program to take 3 positive integers as input and verify whether they
from a pythagorean triplet or not */
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,gre,num,num1,num2,sum,sqr;
clrscr();
cout<<"\nEnter three +ve numbers:";
cout<<"\nEnter first number:";
cin>>a;
cout<<"\nEnter second number:";
cin>>b;
cout<<"\nEnter third number:";
cin>>c;
if(a==0 || b==0 ||c==0)
{
cout<<"\nside zero not possible ";
goto next;
}
num=a*a;
num1=b*b;
num2=c*c;
cout<<"squares of numbers are:";
cout<<"\nsquare of a ="<<num;
cout<<"\nsquare of b ="<<num1;
cout<<"\nsquare of c ="<<num2;
if(a>b && a>c)
{
sqr=sqrt(num1+num2);
gre=a;
cout<<"\nGeater is a";
}
else
if(b>c)
{
sqr=sqrt(num2+num);
gre=b;
cout<<"\nGeater is b";
}
else
{
sqr=sqrt(num+num1);
gre=c;
cout<<"\nGeater is c";
}
if(sqr==gre)
{
cout<<"\nPythagorean Triangle possible ";
}
else
{
cout<<"\nTriangle not possible";
}
next:
getch();
}
No comments:
Post a Comment