Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int triangle(double a,double b,double c,double ha,double *P, double *S){
- if(a <= 0 || b <= 0 || c <= 0 || ha <= 0){
- return -1;
- }
- *P = a + b + c;
- *S = (a * ha) / 2;
- return 0;
- }
- int main(){
- double a,b,c,ha,P,S;
- while(scanf("%lf %lf %lf %lf" , &a, &b, &c, &ha) != EOF){
- if(triangle(a, b, c, ha, &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