Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int triangle(double a, double b, double c, double* P, double* S){
- // 0 -> ok, -1 -> nok
- if (a<=0 ||b<=0 ||c<=0 || a+b<=c || a+c<=b || b+c<=a){
- return -1;
- }
- *P = a + b + c;
- double p = *P / 2.0;
- *S = sqrt(p*(p-a)*(p-b)*(p-c));
- return 0;
- }
- int main(){
- double a, b, c, P, S;
- while (scanf("%lf %lf %lf", &a, &b, &c) != EOF){
- if (triangle(a, b, c, &P, &S) == -1){
- fprintf(stderr, "Invalid triangle sides!\n");
- } else {
- printf("P = %.2lf, S = %.2lf\n", P, S);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement