Advertisement
Vankata17

upgraded triangle in c

Mar 7th, 2022
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <math.h>
  4. int calculate(double a,double b, double c, double* p, double* s){
  5.     if(a <= 0 || b<=0 || c<=0){
  6.         return -1;
  7.     }
  8.     *p =  a+b+c;
  9.     double sp = *p / 2;
  10.     *s = sqrt(sp *(sp -a)*(sp -b)*(sp - c));
  11. return 0;
  12. }
  13. int main(){
  14. double a, b,c, p, s;
  15. printf("Enter sides: ");
  16. scanf("%lf %lf %lf", &a, &b, &c);
  17. if(calculate(a,b,c,&p,&s) == -1){
  18. fprintf(stderr, "Invalid sides\n");
  19. return 1;
  20. }
  21. printf("%.2lf\n",p);
  22. printf("%.2lf",s);
  23.  
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement