Problem statement:- Program to Calculate the surface area and volume of a cone.
Formula:
Surface Area Of Cone(A):
Volume of Cone(V):
V
Formula:
Surface Area Of Cone(A):
Volume of Cone(V):
=
π
r²
h
3
where r=Radius of the cone
h=Height of the cone
Data requirement:-
Input Data:- r,h
where r=Radius of the cone
h=Height of the cone
Data requirement:-
Output Data:- surface_area, volume
Additional Data:-PI
Additional Data:-PI
Program in C
Here is the source code of the C Program to Calculate the surface area and volume of a Cone.
Code:
#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
{
printf("Enter the radius of the cone:");
int r;
scanf("%d",&r);
printf("Enter the height of the cone:");
int h;
scanf("%d",&h);
double surface_area=(PI*r)*(r+sqrt(pow(h,2)+pow(r,2)));//3*PI*r*r
double volume=PI*pow(r,2)*((double)h/3.0);
printf("Surface Area of the cone = %0.2lf\n",surface_area);
printf("Volume of the cone = %0.2lf",volume);
}
#include<math.h>
#define PI 3.14
int main()
{
printf("Enter the radius of the cone:");
int r;
scanf("%d",&r);
printf("Enter the height of the cone:");
int h;
scanf("%d",&h);
double surface_area=(PI*r)*(r+sqrt(pow(h,2)+pow(r,2)));//3*PI*r*r
double volume=PI*pow(r,2)*((double)h/3.0);
printf("Surface Area of the cone = %0.2lf\n",surface_area);
printf("Volume of the cone = %0.2lf",volume);
}
Input/Output:
Enter the radius of the cone:4
Enter the height of the cone:5
Surface Area of the cone = 130.66
Volume of the cone = 83.73
Program in C++
Here is the source code of the C++ Program to Calculate the surface area and volume of a Cone.
Enter the height of the cone:5
Surface Area of the cone = 130.66
Volume of the cone = 83.73
Program in C++
Here is the source code of the C++ Program to Calculate the surface area and volume of a Cone.
Code:
#include<iostream>
#include<cmath>
#define PI 3.14
using namespace std;
int main()
{
cout<<"Enter the radius of the cone:";
int r;
cin>>r;
cout<<"Enter the height of the cone:";
int h;
cin>>h;
double surface_area=(PI*r)*(r+sqrt(pow(h,2)+pow(r,2)));//3*PI*r*r
double volume=PI*pow(r,2)*((double)h/3.0);
cout<<"Surface Area of the cone = "<<surface_area;
cout<<"\nVolume of the cone = "<<volume;
}
Input/Output:#include<cmath>
#define PI 3.14
using namespace std;
int main()
{
cout<<"Enter the radius of the cone:";
int r;
cin>>r;
cout<<"Enter the height of the cone:";
int h;
cin>>h;
double surface_area=(PI*r)*(r+sqrt(pow(h,2)+pow(r,2)));//3*PI*r*r
double volume=PI*pow(r,2)*((double)h/3.0);
cout<<"Surface Area of the cone = "<<surface_area;
cout<<"\nVolume of the cone = "<<volume;
}
Enter the radius of the cone:7
Enter the height of the cone:9
Surface Area of the cone = 404.471
Volume of the cone = 461.58
Program in Java
Enter the height of the cone:9
Surface Area of the cone = 404.471
Volume of the cone = 461.58
Program in Java
Here is the source code of the Java Program to Calculate the surface area and volume of a Cone.
Code:
import java.util.Scanner;
public class SurfaceAreaAndVolumeOfCone {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
double PI=3.14;
System.out.println("Enter the radius of the cone:");
int r=cs.nextInt();
System.out.println("Enter the height of the cone:");
int h=cs.nextInt();
double surface_area=(PI*r)*(r+Math.sqrt(Math.pow(h,2)+Math.pow(r,2)));
double volume=PI*Math.pow(r,2)*((double)h/3.0);
System.out.println("Surface Area of the cone = "+surface_area);
System.out.println("Volume of the cone = "+volume);
cs.close();
}
}
Input/Output:public class SurfaceAreaAndVolumeOfCone {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
double PI=3.14;
System.out.println("Enter the radius of the cone:");
int r=cs.nextInt();
System.out.println("Enter the height of the cone:");
int h=cs.nextInt();
double surface_area=(PI*r)*(r+Math.sqrt(Math.pow(h,2)+Math.pow(r,2)));
double volume=PI*Math.pow(r,2)*((double)h/3.0);
System.out.println("Surface Area of the cone = "+surface_area);
System.out.println("Volume of the cone = "+volume);
cs.close();
}
}
Enter the radius of the cone:
10
Enter the height of the cone:
13
Surface Area of the cone = 828.9982912593013
Volume of the cone = 1360.6666666666665
10
Enter the height of the cone:
13
Surface Area of the cone = 828.9982912593013
Volume of the cone = 1360.6666666666665
Program in Python
Here is the source code of the Python Program to Calculate the surface area and volume of a Cone.
Code:
import math
PI=3.14
r=int(input("Enter the radius of the cone:"))
h=int(input("Enter the height of the cone:"))
surface_area=(PI*r)*(r+math.sqrt(math.pow(h,2)+math.pow(r,2)))
volume=PI*math.pow(r,2)*(h/3.0)
print("Surface Area of the cone= ",surface_area)
print("Volume of the cone = ",volume)
Enter the radius of the cone:100
Enter the height of the cone:50
Surface Area of the cone= 66506.26724674669
Volume of the cone = 523333.3333333334
Enter the height of the cone:50
Surface Area of the cone= 66506.26724674669
Volume of the cone = 523333.3333333334
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box