C++ examples for Operator:Arithmetic Operator
Program to check whether 3 values represent a right triangle.
#include <math.h> #include <stdio.h> #include <iostream> #include <algorithm> bool isRightTriangle(int, int, int); int main(int argc, const char *argv[]) { int a, b, c = 0; std::cout << "Enter three space separated non zero integers: "; std::cin >> a >> b >> c; printf("%d %d %d could%srepresent a right triangle.\n", a, b, c, (isRightTriangle(a, b, c)) ? " " : " not "); return 0;//w w w . j a v a2s .com } bool isRightTriangle(int a, int b, int c) { int hypotenuse = std::max(a, std::max(b, c)); if (hypotenuse == a) return pow(b, 2) + pow(c, 2) == pow(hypotenuse, 2); else if (hypotenuse == b) return pow(a, 2) + pow(c, 2) == pow(hypotenuse, 2); else return pow(a, 2) + pow(b, 2) == pow(hypotenuse, 2); }