(Calculating a Circle’s Diameter, Circumference and Area) Write a program that reads the
radius of a circle (as a double value) and computes and prints the diameter, the circumference and the area. Use the value 3.1 41 59 for Π.
Solution
#include < iostream>
#include < iomanip>
using namespace std;
int main()
{
double radius;
double pi = 3. 14159;
double diameter;
double circum;
double area;
cout << "Enter radius of circle: ";
cin >> radius;
diameter = radius * 2;
circum = radius * 2 * pi;
area = radius * radius * pi;
cout << setprecision( 2 ) << fixed << "The diameter of circle is " << diameter << endl
<< "The circumference of circle is " << circum << endl
<< "The area of circle is " << area << endl;
//for pause
system("PAUSE") ;
return 0;
}
radius of a circle (as a double value) and computes and prints the diameter, the circumference and the area. Use the value 3.1 41 59 for Π.
Solution
#include < iostream>
#include < iomanip>
using namespace std;
int main()
{
double radius;
double pi = 3. 14159;
double diameter;
double circum;
double area;
cout << "Enter radius of circle: ";
cin >> radius;
diameter = radius * 2;
circum = radius * 2 * pi;
area = radius * radius * pi;
cout << setprecision( 2 ) << fixed << "The diameter of circle is " << diameter << endl
<< "The circumference of circle is " << circum << endl
<< "The area of circle is " << area << endl;
//for pause
system("PAUSE") ;
return 0;
}
Post A Comment:
0 comments: