Write a program that defines the named constant PI, const double PI = 3.14159;, which stores the value of π. The program should use PI and the functions listed in Table 6-1 to accomplish the following:
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main(void){
const double PI = 3.14159;
double r;
cout<<"sqrt(PI): "<<sqrt(PI)<<"\n";
cout<<"Enter the radius of a sphere: ";
cin>>r;
double surfaceArea=4*PI*r*r;
double volume=(4.0/3.0)*PI*r*r*r;
cout<<"The surface area of the sphere: "<<surfaceArea<<"\n";
cout<<"The volume of the sphere: "<<volume<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment