/* Program for calculating all Pythagorian Triples within "n <= 200". */ #include<iostream> //include "iostream" header file #include<iomanip> //include "iomanip" header file using namespace std; int main() { int hyp = 1, s1, s2, count = 0; //Declare's Variables while (hyp <= 200) //Control's the value of hypotenuse and also bound check's the program i.e less than 201 { for (s1 = 1; s1 < hyp; s1++) //Control's the value of side1 for (s2 = 1; s2 < hyp; s2++) //Control's the value of side2 if (hyp*hyp == s1*s1 + s2*s2) { count++; //Increment's count by 1 if (count == 1) cout << count << "st Pythagorian Triple is:\t hypotenuse=" << setw(4) << hyp << ", side1=" << setw(4) << s1 << " & side2=" << setw(4) << s2 << endl; //Display's Result else if (count == 2) cout << count << "nd Pythagorian Triple is:\t hypotenuse=" << setw(4) << hyp << ", side1=" << setw(4) << s1 << " & side2=" << setw(4) << s2 << endl; //Display's Result else if (count == 3) cout << count << "rd Pythagorian Triple is:\t hypotenuse=" << setw(4) << hyp << ", side1=" << setw(4) << s1 << " & side2=" << setw(4) << s2 << endl; //Display's Result else cout << count << "th Pythagorian Triple is:\t hypotenuse=" << setw(4) << hyp << ", side1=" << setw(4) << s1 << " & side2=" << setw(4) << s2 << endl; //Display's Result } hyp++; //Increment's 'hyp' by 1 } return 0; }
This blog is about coding in some commonly used "High Level Languages" like C, C++, Java etc. At first, I will post here basic programs written in C++ language only.
Wednesday, December 17, 2014
C++ Program for calculating all Pythagorian Triples within 200.
Labels:
C++ Programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment