Advertisement
vencinachev

Rectangle.c

Mar 9th, 2022
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 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)){
  16.         printf("P = %.2lf, S = %.2lf\n", P, S);
  17.        } else {
  18.         fprintf(stderr, "Invalid sizes!\n");
  19.        }
  20.    }
  21.    return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement