In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of March 31st
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #04 exercise sheet]


In this problem you should submit a file containing the function as described (without any main function). Inside the function do not print anything that was not asked!

[PII025] Is it a Triangle?

Dustin has a genius plan to impress his crush, Suzie! He wants to prove that he’s not just a nerd but also a romantic mathematician. To do this, he’s come up with a special challenge: if he can show that three numbers can form a valid triangle, it will be a sign that their love is "geometrically meant to be!".

A set of three sides forms a valid triangle if it satisfies the triangle inequality theorem, which states that the sum of any two sides must be bigger than the other side, that is, for any three sides a, b, and c it must happen that:

Note that Dustin does not want to consider degenerate triangles of zero area and that is why he does not consider cases where the sum of one side is exactly the same as the sum of the two other sides.

The Problem

Write a function int triangle(int a, int b, int c) that receives three integers a, b, and c and returns 1 if they can represent the lengths of a triangle and 0 otherwise.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ a, b, c ≤ 105       Lengths of the triangle

Submission

You should submit a .c file containing the requested function, without any main function and without printing anything. You can however create additional methods, if you need them.

Mooshak will use the following code to link to your function, read the inputs and call your method, printing its result.

#include <stdio.h>

// Forward declaration of function to implement
int triangle(int, int, int);

int main(void) {

  // Read number of test cases
  int n;
  scanf("%d", &n);

  // For each test case read a,b,c and print
  // the result of calling triangle(c,b,c)
  for (int i=0; i<n; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("triangle(%d,%d,%d) = %d\n", a, b, c, triangle(a,b,c));
  }
  
  return 0;
}

Example Input Example Output
6
2 3 4
6 4 3
1 2 3
3 4 8
3 8 4
8 3 4
triangle(2,3,4) = 1
triangle(6,4,3) = 1
triangle(1,2,3) = 0
triangle(3,4,8) = 0
triangle(3,8,4) = 0
triangle(8,3,4) = 0

Programming II (CCINF1002)
DCC/FCUP - University of Porto