Write a program that defines the named constant PI, const double
PI = 3.14159;, which stores the value of p. The program should use PI
and the functions listed in Table 6-1 to accomplish the following:
a. Output the value of Pi Output the value of Pi.
b. Prompt the user to input the value of a double variable r, which stores the radius of a sphere. The program then outputs the following:
i. The value of 4Pir2, which is the surface area of the sphere.
ii. The value of (4/3)Pir3, which is the volume of the sphere
#include<bits/stdc++.h>
#define PI 3.14159
using namespace std;
int main()
{
cout<<"Value of PI = "<<PI;
double r,sa,vol;
cout<<"\nEnter the radius of sphere ";
cin>>r;
sa=4*PI*r*r;
vol=(4*PI*r*r*r)/3;
cout<<"\nSurface area of sphere = "<<sa;
cout<<"\nVolume of sphere = "<<vol;
}
Comments
Leave a comment