Asked By
zoe143
0 points
N/A
Posted on - 07/21/2011
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.
Answered By
mozak
5 points
N/A
#85931
Code for a right angle triangle
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;
}
Â
Code for a right angle triangle
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