The below code checks whether a triangle is right angled or not by taking input the lengths of all three sides.
Logic: By Pythagoras theorem,
(hypotenuse)^2 = (base)^2+(perpendicular)^2
If the input data satisfies the above equation then the triangle will be a right angle triangle.
Code:
#include <stdio.h>
#include <conio.h>
void main()
{
char x,check;
float first,second,third;
printf("This program checks wheater the trianle is a right angle triangle or not\n\nEnter the lenght of first side:");
scanf("%f",&first);
printf("Enter the length of second side:");
scanf("%f",&second);
printf("Enter the length of third side:");
scanf("%f",&third);
if(first==0&&second==0&&third==0)
printf("invalid input");
else
{
if((first*first)==(second*second)+(third*third))
printf("The triangle is an right angle triangle");
else if((second*second)==(first*first)+(third*third))
printf("The triangle is an right angle triangle");
else if((third*third)==(second*second)+(first*first))
printf("The triangle is an right angle triangle");
else
printf("The triangle is not an right angle triangle");
}
printf("\n\n(*_*) Would you like to run again...(Y/N)");
scanf(" %c", &check);
if(check=='Y'||check=='y')
{
system("cls");
main();
}
printf("\npress any key to continue");
getch();
}
#include <conio.h>
void main()
{
char x,check;
float first,second,third;
printf("This program checks wheater the trianle is a right angle triangle or not\n\nEnter the lenght of first side:");
scanf("%f",&first);
printf("Enter the length of second side:");
scanf("%f",&second);
printf("Enter the length of third side:");
scanf("%f",&third);
if(first==0&&second==0&&third==0)
printf("invalid input");
else
{
if((first*first)==(second*second)+(third*third))
printf("The triangle is an right angle triangle");
else if((second*second)==(first*first)+(third*third))
printf("The triangle is an right angle triangle");
else if((third*third)==(second*second)+(first*first))
printf("The triangle is an right angle triangle");
else
printf("The triangle is not an right angle triangle");
}
printf("\n\n(*_*) Would you like to run again...(Y/N)");
scanf(" %c", &check);
if(check=='Y'||check=='y')
{
system("cls");
main();
}
printf("\npress any key to continue");
getch();
}
Post a Comment