Program to Compute Volume and Surface Area of a Cyllinder
- Write a program to Compute Volume and Surface Area of a Cyllinder in C
- Write a program to Compute Volume and Surface Area of a Cyllinder in C++
- Write a program to Compute Volume and Surface Area of a Cyllinder in Python
- Write a program to Compute Volume and Surface Area of a Cyllinder in PHP
- Write a program to Compute Volume and Surface Area of a Cyllinder in Java
- Write a program to Compute Volume and Surface Area of a Cyllinder in Java Script
- Write a program to Compute Volume and Surface Area of a Cyllinder in C#
Explanation:
Two parallel circular bases and a curved surface joining the bases make up a cylinder, a three-dimensional geometric object. The radius of the base and the cylinder’s height are the two primary factors needed to determine the volume and surface area of a cylinder.
Formulas:
Volume (V): PI x r2 x h
Surface Area (SA): Surface Area = (2 x PI x r2) + (2 x PI x r x h)
r = Radius of the base
h = Height of the cyllinder
Program to Compute Volume and Surface Area of a Sphere
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> #include <math.h> int main() { float radius, height, volume, surfaceArea; printf("Enter the radius of the cylinder: "); scanf("%f", &radius); printf("Enter the height of the cylinder: "); scanf("%f", &height); volume = M_PI * radius * radius * height; surfaceArea = 2 * M_PI * radius * (radius + height); printf("Volume: %.2f\n", volume); printf("Surface Area: %.2f\n", surfaceArea); return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { float radius, height, volume, surfaceArea; cout << "Enter the radius of the cylinder: "; cin >> radius; cout << "Enter the height of the cylinder: "; cin >> height; volume = M_PI * radius * radius * height; surfaceArea = 2 * M_PI * radius * (radius + height); cout << "Volume: " << volume << endl; cout << "Surface Area: " << surfaceArea << endl; return 0; }
import math radius = float(input("Enter the radius of the cylinder: ")) height = float(input("Enter the height of the cylinder: ")) volume = math.pi * radius ** 2 * height surface_area = 2 * math.pi * radius * (radius + height) print(f"Volume: {volume}") print(f"Surface Area: {surface_area}")
<?php $radius = (float)readline("Enter the radius of the cylinder: "); $height = (float)readline("Enter the height of the cylinder: "); $volume = pi() * pow($radius, 2) * $height; $surfaceArea = 2 * pi() * $radius * ($radius + $height); echo "Volume: $volume\n"; echo "Surface Area: $surfaceArea\n"; ?>
import java.util.Scanner; public class Cylinder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the radius of the cylinder: "); double radius = sc.nextDouble(); System.out.print("Enter the height of the cylinder: "); double height = sc.nextDouble(); double volume = Math.PI * Math.pow(radius, 2) * height; double surfaceArea = 2 * Math.PI * radius * (radius + height); System.out.println("Volume: " + volume); System.out.println("Surface Area: " + surfaceArea); } }
const radius = parseFloat(prompt("Enter the radius of the cylinder: ")); const height = parseFloat(prompt("Enter the height of the cylinder: ")); const volume = Math.PI * Math.pow(radius, 2) * height; const surfaceArea = 2 * Math.PI * radius * (radius + height); console.log(`Volume: ${volume}`); console.log(`Surface Area: ${surfaceArea}`);
using System; class Program { static void Main() { Console.Write("Enter the radius of the cylinder: "); double radius = double.Parse(Console.ReadLine()); Console.Write("Enter the height of the cylinder: "); double height = double.Parse(Console.ReadLine()); double volume = Math.PI * Math.Pow(radius, 2) * height; double surfaceArea = 2 * Math.PI * radius * (radius + height); Console.WriteLine("Volume: " + volume); Console.WriteLine("Surface Area: " + surfaceArea); } }