vencinachev

Triangle

Mar 22nd, 2021 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int main()
  5. {
  6.     float a, b, c, p, P, S;
  7.     printf("Enter a: ");
  8.     scanf("%f", &a);
  9.     printf("Enter b: ");
  10.     scanf("%f", &b);
  11.     printf("Enter c: ");
  12.     scanf("%f", &c);
  13.    
  14.     if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || a + c <= b || b + c <= a)
  15.     {
  16.         printf("Invalid triangle!\n");
  17.         return 1;
  18.     }
  19.    
  20.     P = a + b + c;
  21.     p = P / 2;
  22.     S = sqrt(p*(p-a)*(p-b)*(p-c));
  23.     printf("P = %.2f\n", P);
  24.     printf("S = %.2f\n", S);
  25.     return 0;  
  26. }
Add Comment
Please, Sign In to add comment