fork download
  1. #include <stdio.h>
  2.  
  3. #define TRIANGLE_PERIMETER(x,y,z)(x+y+z) // calculate the perimeter of a triangle
  4.  
  5. #define SQUARE_PERIMETER(x)(x*4) // calculate the perimeter of a square
  6.  
  7. #define RECTANGLE_PERIMETER(x,y)((2*x)+(2*y)) // calculate the perimeter of a rectangle
  8.  
  9. #define QUADRILATERAL_PERIMETER(x,y,z,w)(x+y+z+w) // calculate the perimeter of a quadrilateral
  10.  
  11. #define PI 3.14159265358979323846 //define the mathematical constant PI
  12. #define CIRCLE_PERIMETER(x)(PI*(x*x)) // calculate the perimeter of a circle
  13.  
  14. #define SECTOR_PERIMETER(x,y)(x*(y+2)) //calculate the perimeter of a sector
  15.  
  16. int main() {
  17. // Calling the TRIANGLE_PERIMETER macro
  18. float s1 = 5.0;
  19. float s2 = 6.0;
  20. float s3 = 12.0;
  21. float perim1 = TRIANGLE_PERIMETER(s1,s2,s3);
  22. printf("Perim. of the triangle is: %f\n", perim1);
  23.  
  24. // Calling the SQUARE_PERIMETER macro
  25. float s1_new = 5.0;
  26. float perim2 = SQUARE_PERIMETER(s1_new);
  27. printf("Perim. of the square is: %f\n", perim2);
  28. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Perim. of the triangle is: 23.000000
Perim. of the square is: 20.000000