MilaDimitrovaa

triangle.c

Mar 19th, 2022
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int triangle(double a,double b,double c,double ha,double *P, double *S){
  4. if(a <= 0 || b <= 0 || c <= 0 || ha <= 0){
  5.     return -1;
  6. }
  7. *P = a + b + c;
  8. *S = (a * ha) / 2;
  9. return 0;
  10. }
  11.  
  12. int main(){
  13. double a,b,c,ha,P,S;
  14. while(scanf("%lf %lf %lf %lf" , &a, &b, &c, &ha) != EOF){
  15.     if(triangle(a, b, c, ha, &P, &S) == -1){
  16.         fprintf(stderr, "Invalid triangle sides!\n");
  17.     }else{
  18.         printf("P = %.2lf, S = %.2lf\n",P, S);
  19.     }
  20.  }
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment