- 2
Write Programme In C++ for finding Right angle triangle using Pythagoras Theorem
3 Respuestas
0
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
int varOne;
int varTwo;
string unknown;
cout << " ";
cout << "|\\" << endl << "a ";
cout << "| \\ c" << endl << " ";
cout << "| \\" << endl << " ";
cout << "|___\\" << endl << " ";
cout << " b " << endl << endl;
cout << "Which variable are you looking for? ";
cin >> unknown;
cout << unknown << endl;
if(unknown == "a" || unknown == "b"){
if(unknown == "a"){
cout << "What is b? ";
} else {
cout << "What is a? ";
}
cin >> varOne;
cout << varOne << endl;
cout << "What is c? ";
cin >> varTwo;
cout << varTwo << endl;
cout << "The variable " << unknown << " is: " << sqrt((double)varTwo*varTwo - varOne*varOne);
} else if(unknown == "c"){
cout << "What is a? ";
cin >> varOne;
cout << varOne << endl;
0
cout << "What is b? ";
cin >> varTwo;
cout << varTwo << endl;
cout << "The variable " << unknown << " is: " << sqrt((double)varOne*varOne + varTwo*varTwo);
} else {
cout << "Error, the variable you are looking for is unrecognized. The variables you can look for are a, b, or c." << endl;
}
/*
cout << "a: "; cin >> a; cout << a << endl;
cout << "b: "; cin >> b; cout << b << endl;
cout << "c: "; cin >> c; cout << c << endl;
*/
return 0;
}
0
That is my code. I hope this is what you are looking for.