Chapter 4:
Input And Output
Programming Exercise
Problem # 2:
Write a program that inputs radius of sphere from the user. Calculate its volume and surface area using the formula Area = 4πr2 and circumference = 4/3πr3 where PI=3.14.
Solution:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
const float PI=3.14;
float area, circumference, radius;
cout<<"Input radius of spehere: ";
cin>>radius;
area = 4*PI*pow(radius,2);
circumference = (4/3)*PI*pow(radius,3);
cout<<"Area: "<<area<<endl;
cout<<"Circumference: "<<circumference<<endl;
return 0;
}
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
const float PI=3.14;
float area, circumference, radius;
cout<<"Input radius of spehere: ";
cin>>radius;
area = 4*PI*pow(radius,2);
circumference = (4/3)*PI*pow(radius,3);
cout<<"Area: "<<area<<endl;
cout<<"Circumference: "<<circumference<<endl;
return 0;
}
Code Screenshot:
Output:
Let me know in the comment section if you have any question.
Previous Post:
1. Program that prints a text of 4 lines consisting of characters, integer values and floating point values using cout statement.
Comments
Post a Comment