Write a C program that asks for the radius of a circle and c

Write a C++ program that asks for the radius of a circle and calls a function to compute diameter; and calls a function to compute circumference. Each function returns the value it computes to the main program where the value is sent to the output via a cout statement.

Solution

#include <iostream>
using namespace std;
double computeDiameter(double radius) //function to compute diameter
{
   double diameter = 2*radius;
   return diameter;
}
double computeCircumference(double diameter) //function to compute circumference
{
   double circumference = 3.1412 * diameter;
   return circumference;
}

int main()
{
   double radius,diameter,circumference;
   cout<<\"Enter the radius of the circle\";
   cin>>radius;
   diameter =computeDiameter(radius); //function calls
   circumference = computeCircumference(diameter);
  
   cout<<\"\ Diameter of the circle : \"<<diameter;
   cout<<\"\ Circumference of the circle : \"<<circumference;
  
   return 0;
}

output:

 Write a C++ program that asks for the radius of a circle and calls a function to compute diameter; and calls a function to compute circumference. Each function

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site