Percentage change in Hemisphere volume if radius is changed
Last Updated :
07 Aug, 2022
Given that the radius of a hemisphere is changed by a fixed percentage so, the target is to calculate the percentage changed in the volume of the hemisphere.
Examples:
Input: r = 20%
Output: 72.80%
Input: r = 70%
Output: 391.30 %
Approach:
- Let, the radius of the hemisphere =
- Given percentage increase =
- Volume before increase =
- New radius after increase =
- So, new volume =
- Change in volume =
- Percentage increase in volume
Below is the implementation of the above approach:
CPP
#include <iostream>
#include <math.h>
using namespace std;
void new_vol( double x)
{
if (x > 0) {
cout << "% change in the "
<< "volume of the hemisphere: "
<< pow (x, 3) / 10000 + 3 * x
+ (3 * pow (x, 2)) / 100
<< "%"
<< " increase\n" ;
}
else if (x < 0) {
cout << "% change in the "
<< "volume of the hemisphere: "
<< pow (x, 3) / 10000 + 3 * x
+ (3 * pow (x, 2)) / 100
<< "% decrease\n" ;
}
else {
cout << "Volume remains the same." ;
}
}
int main()
{
double x = -10.0;
new_vol(x);
return 0;
}
|
Java
class GFG
{
static void new_vol( double x)
{
if (x > 0 )
{
System.out.print( "% change in the "
+ "volume of the hemisphere: "
+ (Math.pow(x, 3 ) / 10000 + 3 * x
+ ( 3 * Math.pow(x, 2 )) / 100 )
+ "%"
+ " increase\n" );
}
else if (x < 0 )
{
System.out.print( "% change in the "
+ "volume of the hemisphere: "
+ (Math.pow(x, 3 ) / 10000 + 3 * x
+ ( 3 * Math.pow(x, 2 )) / 100 )
+ "% decrease\n" );
}
else
{
System.out.print( "Volume remains the same." );
}
}
public static void main(String[] args)
{
double x = - 10.0 ;
new_vol(x);
}
}
|
Python
def new_vol(x):
if (x > 0 ):
print ( "% change in the volume of the hemisphere: " , pow (x, 3 ) / 10000 + 3 * x + ( 3 * pow (x, 2 )) / 100 , "% increase" )
elif (x < 0 ):
print ( "% change in the volume of the hemisphere: " , pow (x, 3 ) / 10000 + 3 * x + ( 3 * pow (x, 2 )) / 100 , "% decrease" )
else :
print ( "Volume remains the same." )
x = - 10.0
new_vol(x)
|
C#
using System;
class GFG
{
static void new_vol( double x)
{
if (x > 0)
{
Console.Write( "% change in the "
+ "volume of the hemisphere: "
+ (Math.Pow(x, 3) / 10000 + 3 * x
+ (3 * Math.Pow(x, 2)) / 100)
+ "%"
+ " increase\n" );
}
else if (x < 0)
{
Console.Write( "% change in the "
+ "volume of the hemisphere: "
+ (Math.Pow(x, 3) / 10000 + 3 * x
+ (3 * Math.Pow(x, 2)) / 100)
+ "% decrease\n" );
}
else
{
Console.Write( "Volume remains the same." );
}
}
public static void Main()
{
double x = -10.0;
new_vol(x);
}
}
|
Javascript
function new_vol(x)
{
if (x > 0)
{
document.write( "% change in the "
+ "volume of the hemisphere: "
+ (Math.pow(x, 3) / 10000 + 3 * x
+ (3 * Math.pow(x, 2)) / 100)
+ "%"
+ " increase\n" );
}
else if (x < 0)
{
document.write( "% change in the "
+ "volume of the hemisphere: "
+ (Math.pow(x, 3) / 10000 + 3 * x
+ (3 * Math.pow(x, 2)) / 100)
+ "% decrease\n" );
}
else
{
document.write( "Volume remains the same." );
}
}
var x = -10.0;
new_vol(x);
|
Output: % change in the volume of the hemisphere: -27.1% decrease
Time Complexity: O(1)
Auxiliary Space: O(1) as using only constant variables
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...