MilaDimitrovaa

rectangle

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