Q:

Program to calculate Volume of Cone

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the volume of cone in different programming languages, firstly we have to know about what is cone and what is the formula to find volume of it?

What is Cone?

A cone is a 3-D geometric shape. This shape consist the base of circle shape and the curved surface pointing towards top.

Volume of Cone is the total space acquired by the cone.

 

Volume of Cone = 1/3(pi * r * r * h)  

Where, r is the radius, h is the height and value of pi is 3.14  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program of calculating the volume of a cone in different Programming languages

Program 1: Write a Program in C language:

// This C program which uses a function to calculate the volume of a cone.  
#include <stdio.h>  
#define pi 3.14  
float find_Volume_of_cone(float r, float h) // It is a function to find volume   
{   
float Volume_of_cone;  
Volume_of_cone= (pi *  r * r * h) / 3 ;   
// It is a formula for calculating a volume of cone   
return (Volume_of_cone);   
}   
float main()   
{   
float r;   
float h;  
printf("Enter the radius of the cone:");   
scanf("%f",&r);  
printf("Enter the height of the cone:");   
scanf("%f",&h);  
float x = find_Volume_of_cone(r,h);  
printf("Volume of the cone is: %f",x);     
return 0;   
}  

 

Output of Above C program:

Enter the radius of the cone: 5
Enter the height of the cone: 10
Volume of the cone is: 261.666656

 

Program 2: Write a Program in Java language:

// This a Java program which calculates the volume of a cone.  
class findvolume {   
static float find_Volume_of_cone(float r, float h)   
{   
final float pi = (float) 3.141592653589793;   
float Volume_of_cone;  
Volume_of_cone=  (pi *  r * r * h) / 3 ; // It is a formula for calculating the volume of cone   
return(Volume_of_cone);   
}   
// Driver method   
public static void main(String[] args)   
{   
float radius = 5, h = 10;   
System.out.println("The Volume of a cone in Java:");  
System.out.println(find_Volume_of_cone(radius,h));   
}   
}  

 

Output of Above Java program:

The Volume of a cone in Java:
261.7994

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which calculates the volume of a cone.    
// Function to find volume   
function find_Volume_of_cone($r, $h)   
{     
$pi =  3.14;  
$Volume_of_cone =  ($pi *  $r * $r * $h) / 3 ; // It is a formula which calculates the volume  and store the value in the volume_of_cone variable.   
return ($Volume_of_cone);   
}   
  
$radius = 10;   
$height = 10;  
  
echo find_Volume_of_cone($radius, $height);   

 

Output of Above PHP program:

1046.6666666667

 

Program 4: Write a Program in Python programming language.

# This is a python program which calculates the volume of a cone.   
# It is a function to calculate the volume of cone  
import math  
pi = math.pi  
  
def find_Volume_of_cone(r,h):  
    return (pi *  r * r * h ) / 3 # It is a formula which calculates the value of volume.   
  
radius = 5  
height = 10  
print(find_Volume_of_cone(radius, height))  

 

Output of Above Python program:

261.79938779914943

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Miscellaneous Programs Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Program to calculate the Perimeter of Hexa... >>
<< Pyramid Programs in VB (Visual Basic)...