TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

program to calculate the volume of sphere

program to calculate the volume of sphere on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph etc.

<< Back to PROGRAM

Program to calculate the volume of the sphere

A sphere is a perfectly round geometrical object in 3-dimensional space. It is the set of all the points located a particular distance away from a particular point called center. It is perfectly symmetrical and has no edges or vertices.

Formula

Volume= (4/3)*pie*r3

Algorithm

  1. Define the radius of the sphere
  2. Define the pie and assign (22/7)
  3. Calculate the volume of the sphere as (4/3)*pie*r3
  4. Assign the volume of the sphere to volume_of_sphere
  5. Print the volume of the sphere.

Complexity

O(1)


Solution

C Program

#include 
int main()
{
    int radius=48;
    float pie=3.14285714286;
    double volume=(4.0/3.0)*pie*(radius*radius*radius);
    printf("Volume of the sphere=%f",volume);
}

Output:

Volume of the sphere=463433.132812 

PHP Program

<?php  
    $radius=48;
    $pie=3.14285714286;
    $volume=(4/3)*$pie*($radius*$radius*$radius);
    echo "Volume of the Sphere=";
    echo $volume;
?>  

Output:

Volume of the Sphere=463433.14285756  

Java Program

public class sphere{
        public static void main(String args[])
    {
    int radius=48;
    double pie=3.14285714286;
    double volume=(4.0/3.0)*pie*(radius*radius*radius);
    System.out.println("Volume of the sphere="+volume);
     }
}

Output:

Volume of the sphere=463433.14285756415

C# Program

using System;
public class Program
{
	public static void Main()
	{
		
  int radius=48;
    double pie=3.14285714286;
    double volume=(4.0/3.0)*pie*(radius*radius*radius);
    
   Console.WriteLine("Volume of sphere="+volume);
	}
}

Output:

Volume of sphere=463433.142857564

Python Program

radius=48
pie=3.14285714286
volume=(4.0/3.0)*pie*(radius*radius*radius)
print("volume of the sphere="+str(volume))

Output:

volume of the sphere=463433.14285756415   

Next Topic#




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf