Advertisement
18126

HW2ex2

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