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


I have used CodeBlocks 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

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


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

Result

C++ language techstudy.org

     





Related Topics




Popular Posts