Program to determine if 3 values make a triangle. - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Program to determine if 3 values make a triangle.

Demo Code

#include <stdio.h>
#include <iostream>

bool isTriangle(int, int, int);

int main(int argc, const char *argv[]) {
    int a, b, c = 0;

    std::cout << "Enter 3 space separated nonzero integers: ";
    std::cin >> a >> b >> c;

    printf("%d %d %d could%srepresent a triangle\n", a, b, c,
           (isTriangle(a, b, c) ? " " : " not "));

    return 0;/*from  www  .jav a2s. c o  m*/
}
bool isTriangle(int a, int b, int c) {
    if ((a + b > c) && (a + c > b) && (b + c > a)) return true;
    return false;
}

Result


Related Tutorials