I wrote code of determining if three edges (input) can form a triangle, but when the input is "1.1 2.2 3.3", there's a problem. Here's my code:
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c;
float s, area;
scanf("%f %f %f", &a, &b, &c);
if (a > 0 && b > 0 && c > 0) {
if (a + b > c && b + c > a && a + c > b) {
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("%f", area);
} else
printf("error input");
} else {
printf("error input");
}
}
When I enter "1.1 2.2 3.3", the output is "0.001380", but it's supposed to be "error input" because 1.1+2.2==3.3. Besides, when I enter other floats like "2.2 3.3 5.5", the output is "error input". Could someone please explain why?