Code for a right angle triangle

Asked By 0 points N/A Posted on -
qa-featured

Hi! I want design a code for a TRIANGLE in such a way that first the code should ask for the three INPUTS from the user. The executer will check if all three sides are equal it will show a message that triangle is RIGHT-TRIANGLE. Otherwise it will show a message that enter three inputs again. This LOOP will be continued until you get RIGHT-ANGLE triangle.

SHARE
Best Answer by Clair Charles
Answered By 5 points N/A #85931

Code for a right angle triangle

qa-featured

Source Code
——————————————————————————–
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
double legA;
double legB;
double legC;

cout << "Please enter three sides of a triangle: ";
cin >> legA; cin >> legB; cin >> legC;

legC = pow(legC, 2.0);

if (legC == pow(legA, 2.0) + pow(legB, 2.0))
{
cout << "This is a right triangle. " << endl;
cout << endl;
}
else
{
cout << "This is NOT a right triangle. " << endl;
cout << endl;
}

// Testing Results
cout << "legC = " << legC << endl;
cout << "legA + legB = " << pow(legA, 2.0) + pow(legB, 2.0) << endl;

return 0;
}
 

Best Answer
Best Answer
Answered By 15 points N/A #85932

Code for a right angle triangle

qa-featured

The following code will help you create the triangle as you want using C#, but then you will have to customize it appropriately to suit your situation.

There are two sample codes:

First code

#include<stdio.h>
#include<conio.h>
void main()
{
int space=35,lines,l,s,j,c,i,L;
clrscr();
printf("Enter Number Of Line:");
scanf("%d",&l);
for(lines=0;lines<l;lines++)
{
for(s=0;s<space;s++)
printf(" ");
for(j=1;j<=lines+1;j++)
{
L=lines;
for(i=1,c=1;i<j;i++,L–)
c=c*L/i;
printf(" *");//This line prints *
}
printf("nn");
space–;
}
getch();
}

Second Code
printf(" *");
with
printf(" %d",c);
#include<stdio.h>
#include<conio.h>
void main()
{
int space=35,lines,l,s,j,c,i,L;
clrscr();
printf("Enter Number Of Line:");
scanf("%d",&l);
for(lines=0;lines<l;lines++)
{
for(s=0;s<space;s++)
printf(" ");
for(j=1;j<=lines+1;j++)
{
L=lines;
for(i=1,c=1;i<j;i++,L–)
c=c*L/i;
printf(" %d",c);
}
printf("nn");
space–;
}
getch();
}

You will need to copy either of them in the visual basic editor, and them modify them appropriately.

 

-Clair charles

Related Questions