Program to Calculate the surface area and volume of a Hemisphere

Problem statement:-  Program to Calculate the surface area and volume of a Hemisphere.

Formula:

Surface Area Of Hemisphere(A):  3𝛑r²

Volume of Hemisphere(V): (2/3)πr3

where r=Radius of the Hemisphere

Data requirement:-

   Input Data:- r

  Output Data:- surface_area, volume
   
  Additional Data:-PI

Program in C

Here is the source code of the C Program to Calculate the surface area and volume of a Hemisphere.

Code:

#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
{
    printf("Enter the radius of the Hemisphere:");
    int r;
    scanf("%d",&r);
    double surface_area=3*PI*pow(r,2);//3*PI*r*r
    double volume=(2.0/3.0)*PI*pow(r,3);
    printf("Surface Area of the Hemisphere = %0.2lf\n",surface_area);
    printf("Volume of the Hemisphere = %0.2lf",volume);
}

Input/Output:
Enter the radius of the Hemisphere:5
Surface Area of the Hemisphere = 235.50
Volume of the Hemisphere = 261.67

Program in C++

Here is the source code of the C++ Program to Calculate the surface area and volume of a Hemisphere.

Code:

#include<iostream>
#include<cmath>
#define PI 3.14
using namespace std;
int main()
{
    cout<<"Enter the radius of the Hemisphere:";
    int r;
    cin>>r;
    double surface_area=3*PI*pow(r,2);//3*PI*r*r
    double volume=(2.0/3.0)*PI*pow(r,3);
    cout<<"Surface Area of the Hemisphere = "<<surface_area;
    cout<<"\nVolume of the Hemisphere = "<<volume;
}

Input/Output:
Enter the radius of the Hemisphere:7
Surface Area of the Hemisphere = 461.58
Volume of the Hemisphere = 718.013

Program in Java
  
Here is the source code of the Java Program to Calculate the surface area and volume of a Hemisphere.

Code:

import java.util.Scanner;
public class SurfaceAreaAndVolumeOfHemisphere {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the radius of the Hemisphere:");
    int r=cs.nextInt();
    double PI=3.14;
    double surface_area=3*PI*Math.pow(r,2);//3*PI*r*r
    double volume=(2.0/3.0)*PI*Math.pow(r,3);
    System.out.println("Surface Area of the Hemisphere = "+surface_area);
    System.out.println("Volume of the Hemisphere = "+volume);
     cs.close();
}
}

Input/Output:
Enter the radius of the Hemisphere:
10
Surface Area of the Hemisphere = 942.0
Volume of the Hemisphere = 2093.3333333333335


Program in Python
  
Here is the source code of the Python Program to Calculate the surface area and volume of a Hemisphere.

Code:

import math
r=int(input("Enter the radius of the Hemisphere:"))
PI=3.14
surface_area=3*PI*math.pow(r,2)
volume=(2.0/3.0)*PI*math.pow(r,3)
print("Surface Area of the Hemisphere = ",surface_area)
print("Volume of the Hemisphere = ",volume)

Input/Output:

Post a Comment

0 Comments