Q:

Write a Program to calculate the surface Area of Cone

belongs to collection: Miscellaneous Programs Examples

0

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

What is Cone?

A cone is a half-part of the sphere.

Surface Area of Cone is the total number of square units which exactly cover the cone surface.

 

Surface Area of Cone = pi * r * s + pi * r * r  

Where, r is the radius of cone  

All Answers

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

Program of calculating the surface area 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 surface area of a cone.  
#include <stdio.h>  
#define pi 3.141592653589793   
float find_SurfaceArea_of_cone(float r, float s) // It is a function to find surface area   
{   
float SurfaceArea_of_cone;  
SurfaceArea_of_cone= pi * r * s + pi * r * r ; // It is a formula for calculating a surface area of cone   
return (SurfaceArea_of_cone);   
}   
float main()   
{   
float r,s ;   
printf("Enter the radius of the cone:");   
scanf("%f",&r);  
printf("Enter the slant height of the cone:");   
scanf("%f",&s);  
  
printf("Surface Area of the cone is: %.2f", find_SurfaceArea_of_cone(r,s));     
return 0;   
}  

 

Output of Above C program:

Enter the radius of the cone: 5
Enter the slant height of the cone: 10
Surface Area of the cone is: 235.62

 

Program 2: Write a Program in Java language:

// This a  Java program which calculates the surface area of a cone.  
class findsurface_area {   
static float find_SurfaceArea_of_cone(float r, float s)   
{   
 final float pi = (float) 3.141592653589793;   
float SurfaceArea_of_cone;  
SurfaceArea_of_cone= pi * r * s + pi * r * r; // It is a formula for calculating the surface area of cone   
return(SurfaceArea_of_cone);   
}   
// Driver method   
public static void main(String[] args)   
{   
float radius = 2;   
float slant_height=10;  
System.out.println("The Surface Area of a cone in Java:");  
System.out.println(find_SurfaceArea_of_cone(radius,slant_height));   
}   
}  

 

Output of Above Java program:

The Surface Area of a cone in Java:
75.398224

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which calculates the surface area of a cone.    
// Function to find surface area   
function find_SurfaceArea_of_cone($r, $l)   
{     
$pi= 3.14;  
$SurfaceArea_of_cone = $pi * $r * $l + $pi * $r * $r; // It is a formula which calculates the surface area  and store the value in the Surface Area_of_cone variable.   
return ($SurfaceArea_of_cone);   
}   
$side = 2;  
$l=10;   
echo find_SurfaceArea_of_cone($side, $l);   
?>  

 

Output of Above PHP program:

75.36

 

Program 4: Write a Program in Python programming language.

# This is a python program which calculates the surface area of a cone.   
# It is a function to calculate the surface area of cone  
import math  
pi = math.pi  
def surfacearea_of_cone(r, s):  
    return pi * r * s + pi * r * r # It is a formula which calculates the value of Surface Area.   
# Main Code  
radius = float(2)  
slant_height = float(10)  
print( "Surface Area Of Cone : ", surfacearea_of_cone (radius, slant_height) )  

 

Output of Above Python program:

Surface Area of Cone:  75.39822368615503

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 Surface Area of H... >>
<< Write a Program to calculate the Area of Rhombus...