In: Computer Science
Write a program that reads the radius of a sphere and calculates it's volume and surface area. Format results to 4 decimal places. The radius=3.2 Your program should output volume and surface area. Repeat same steps for program2, but this time use the following input values:
a= ꟷ2.4 , b = 4.5 . Your program should output sum, Fun1, and Fun2. It's for C++
Answer:
Please post the program2 correctly no sufficient infromation
Here is the c++ code for program one
Raw code:
//headers
#include <iostream>
#include<iomanip>
//namespace standard
using namespace std;
//pi constant
const float PI = 3.14;
//function to calculater surfaceArea
float surface_area(float radius){
float surfaceArea=4*PI*(radius*radius);
return surfaceArea;
}
//function to calculate volume of sphere
float volume(float radius){
float vol=4/3*PI*(radius*radius*radius);
return vol;
}
//main
int main() {
//setting precison to 5 to show upto four decimal points
cout<<setprecision(5)<<endl;
//radius
float radius=3.2;
//calling function passing the radius
cout<<"Surface area: "<<surface_area( radius)<<endl;
cout<<"Volume: "<<volume(radius)<<endl;
}
Editor:
output:
Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.
"Please refer to the screenshot of the code to understand the indentation of the code".
Thank you! Do upvote.