Write C program to find diameter, circumference and area of circle using function


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to find diameter, circumference and area of circle using function


  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. //All Function declaration
  5. double getDiameter(double radius);
  6. double getCircumference(double radius);
  7. double getArea(double radius);
  8.  
  9.  
  10. int main()
  11. {
  12. float radius, diameter, circle, area;
  13.  
  14. // Inputting radius of circle from user
  15. printf("Enter radius of circle: ");
  16. scanf("%f", &radius);
  17.  
  18. diameter = getDiameter(radius); // Calling getDiameter function
  19. circle = getCircumference(radius); // Calling getCircumference function
  20. area = getArea(radius); // Calling getArea function
  21.  
  22. printf("Diameter of the circle = %.2f units\n", diameter);
  23. printf("Circumference of the circle = %.2f units\n", circle);
  24. printf("Area of the circle = %.2f sq. units", area);
  25.  
  26. return 0;
  27. }
  28.  
  29. // Calculating diameter of circle whose radius is given
  30.  
  31. double getDiameter(double radius)
  32. {
  33. return (2 * radius);
  34. }
  35.  
  36.  
  37. //Calculating circumference of circle whose radius is given
  38.  
  39. double getCircumference(double radius)
  40. {
  41. return (2 * M_PI * radius); // PI = 3.14
  42. }
  43.  
  44. //Finding area of circle whose radius is given
  45.  
  46. double getArea(double radius)
  47. {
  48. return (M_PI * radius * radius); // PI = 3.14
  49. }
  50.  

Result

C language

     





Related Topics




Popular Posts