Advertisement
Guest User

Untitled

a guest
Feb 19th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. int main(void)
  7. {
  8.     float width, length, aREA, pERIMETER;
  9.     int answer;
  10.  
  11.     printf("Please enter the width of the rectangle: ");
  12.     scanf("%4f", &width);
  13.  
  14.     printf("\nPlease enter the length of the rectangle: ");
  15.     scanf("%4f", &length);
  16.  
  17.     aREA = width * length;
  18.     pERIMETER = 2*(width + length);
  19.  
  20.     printf("\nEnter 1 to calculate the area and 2 to calculate perimeter.\n");
  21.     scanf(" %d", &answer);
  22.  
  23.     if(answer == 1){
  24.         printf("\nThe area is %.1f.\n", aREA);
  25.     }else if(answer == 2){
  26.         printf("\nThe perimeter is %.1f.\n", pERIMETER);
  27.     }else{
  28.         printf("\nPlease enter 1 or 2.\n");
  29.     }
  30.  
  31.     getch();
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement