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