Problem:
Write a program to calculate area, perimeter and volume of a sphere from radius input by user.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
float a,p,v,r;
const float PI=3.14;
cout<<"enter radius:";
cin>>r;
a=4*PI*r*r;
p=2*PI*r;
v=4/3*PI*r*r*r;
cout<<"the area of sphere is:"<<a<<endl<<"the perimeter of sphere is:"<<p<<endl<<"the volume of sphere is:"<<v;
getch();
}
#include<conio.h>
using namespace std;
int main ()
{
float a,p,v,r;
const float PI=3.14;
cout<<"enter radius:";
cin>>r;
a=4*PI*r*r;
p=2*PI*r;
v=4/3*PI*r*r*r;
cout<<"the area of sphere is:"<<a<<endl<<"the perimeter of sphere is:"<<p<<endl<<"the volume of sphere is:"<<v;
getch();
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
Program to calculate area and perimeter of a rectangle.