Vasilena

AreaOfRectangle

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