Problem statement:- Program to Find the Surface area and volume of a sphere.
Data requirement:-
Input Data:-radius
Output Data:-surfaceArea, volume
Output Data:-surfaceArea, volume
Program in C
Here is the source code of the C Program to Find the surface area and volume of a sphere.
Code:
#include <stdio.h>
int main(){
double radius;
double surfaceArea,volume;
printf("Enter the radius of sphere:");
scanf("%lf",&radius);
surfaceArea=4*3.14*radius*radius;
volume=(4/3.0)*3.14*radius*radius*radius;
printf("Surface Area of the sphere= %lf",surfaceArea);
printf("\nVolume of the sphere= %lf",volume);
return 0;
}
Input/Output:
Enter the radius of sphere:10
Surface Area of the sphere= 1256.000000
Volume of the sphere= 4186.666667
Surface Area of the sphere= 1256.000000
Volume of the sphere= 4186.666667
Program in C++
Here is the source code of the C++ Program to Find the surface area and volume of a sphere.
Code:
#include <iostream>
using namespace std;int main()
{
double radius;
double surfaceArea,volume;
cout<<"Enter the radius of sphere:";
cin>>radius;
surfaceArea=4*3.14*radius*radius;
volume=(4/3.0)*3.14*radius*radius*radius;
cout<<"Surface Area of the sphere= "<<surfaceArea;
cout<<"\nVolume of the sphere= "<<volume;
return 0;
}
Input/Output:
Enter the radius of sphere:3.5
Surface Area of the sphere= 153.86
Volume of the sphere= 179.503
Surface Area of the sphere= 153.86
Volume of the sphere= 179.503
Program in Java
Here is the source code of the Java Program to Find the surface area and volume of a sphere.
Code:
import java.util.Scanner;
public class SurfaceAreaVolumeSphere {public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
double radius;
double surfaceArea,volume;
System.out.println("Enter the radius of sphere:");
radius=cs.nextDouble();
surfaceArea=4*3.14*radius*radius;
volume=(4/3.0)*3.14*radius*radius*radius;
System.out.println("Surface Area of the sphere= "+surfaceArea);
System.out.println("\nVolume of the sphere= "+volume);
cs.close();
}}
Input/Output:
Enter the radius of sphere:
7
Surface Area of the sphere= 615.44
Volume of the sphere= 1436.0266666666666
7
Surface Area of the sphere= 615.44
Volume of the sphere= 1436.0266666666666
Program in Python
Here is the source code of the Python Program to Find the surface area and volume of a sphere.
Code:
radius=int(input("Enter radius of a sphere :"))
surfaceArea=4*3.14*radius*radius
volume=(4/3)*3.14*radius*radius*radius
print("Surface Area of the sphere =",surfaceArea)
print("Volume of the sphere =",volume)
Input/Output:
Enter radius of a sphere :5
Surface Area of the sphere = 314.0
Volume of the sphere = 523.3333333333334
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box