Percentage change in Hemisphere volume if radius is changed

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 = a
  • Given percentage increase = x%
  • Volume before increase = \frac{2}{3} * 3.14*a^3
  • New radius after increase = a + \frac{ax}{100}
  • So, new volume = \frac{2}{3}*3.14*(a^3 + (\frac{ax}{100})^3 + \frac{3a^3x}{100} + \frac{3a^3x^2}{10000})
  • Change in volume = \frac{2}{3}*3.14*((\frac{ax}{100})^3 + \frac{3a^3x}{100} + \frac{3a^3x^2}{10000})
  • Percentage increase in volume
    = (\frac{2}{3}*3.14*((\frac{ax}{100})^3 + \frac{3a^3x}{100} + \frac{3a^3x^2}{10000})/\frac{2}{3}*3.14*a^3) * 100
    = \frac{x^3}{10000} + 3x + \frac{3x^2}{100}

Below is the implementation of the above approach:

CPP

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to find percentage change
// in hemisphere volume wrt change in radius
  
#include <iostream>
#include <math.h>
using namespace std;
  
// Function to find the change
// in hemispheric volume
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.";
    }
}
  
// Driver code
int main()
{
  
    // Get the change in radius
    double x = -10.0;
  
    // Calculate the change in hemispheric volume
    new_vol(x);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to find percentage change
// in hemisphere volume wrt change in radius
class GFG
{
  
// Function to find the change
// in hemispheric volume
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.");
    }
}
  
// Driver code
public static void main(String[] args)
{
  
    // Get the change in radius
    double x = -10.0;
  
    // Calculate the change in hemispheric volume
    new_vol(x);
}
}
  
// This code is contributed by Rajput-Ji

chevron_right


Python

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to find percentage change
# in hemisphere volume wrt change in radius
  
  
# Function to find the change
# in hemispheric volume
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.")
# Driver code
  
# Get the change in radius
x = -10.0
  
# Calculate the change in hemispheric volume
new_vol(x)
  
# This code is contributed by mohit kumar 29

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to find percentage change
// in hemisphere volume wrt change in radius
using System;
  
class GFG
{
  
    // Function to find the change
    // in hemispheric volume
    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.");
        }
    }
      
    // Driver code
    public static void Main()
    {
      
        // Get the change in radius
        double x = -10.0;
      
        // Calculate the change in hemispheric volume
        new_vol(x);
    }
}
  
// This code is contributed by AnkitRai01

chevron_right


Output:

% change in the volume of the hemisphere: -27.1% decrease


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.