2. Program that inputs radius of sphere from the user and calculate its volume and surface area.

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;
}

Code Screenshot:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Output:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

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