Question #11681

Write a program that defines the named constant PI, const double PI = 3.1419; which stores the value of p. The program should use PI and some of the math functions you learn previously to accomplish the tasks. In the main program, prompt the user to input the value of a double variable r, which stores the radius of a circle. The program then call the following functions and output the appropriate results.
(a) The value of πr2, which is the area of the circle.
(b) The value of 2πr which is the circumference of the circle.

Expert's answer

# include<iostream.h>

# include<conio.h>

double pi = 3.1419, r;

double area(double r){

return pi*r*r;

}

double circumference(double r){

return 2*pi*r;

}

void main(){

cout<<"Enter the radius of a circle: ";

cin>>r;

cout<<"The area of a circle is "<<area(r)<<"\r\n";

cout<<"The circumference of a circle is "<<circumference(r)<<"\r\n";

getch();

}

# include<conio.h>

double pi = 3.1419, r;

double area(double r){

return pi*r*r;

}

double circumference(double r){

return 2*pi*r;

}

void main(){

cout<<"Enter the radius of a circle: ";

cin>>r;

cout<<"The area of a circle is "<<area(r)<<"\r\n";

cout<<"The circumference of a circle is "<<circumference(r)<<"\r\n";

getch();

}

## Comments

## Leave a comment