# Find the volume of a torus

Here given code implementation process.

``````/*
C Program
Find the volume of a torus
*/
#include <stdio.h>

#include <math.h>

//Calculate volume of a torus by given small and large radius
void torus_volume(double r, double R)
{
// Formula of torus volume
// 2 × π² × R × r²
// here r is radius of small circle
// R is radius of large circle
//Display given inputs
printf("\nGiven Radius of r: %lf Radius of R : %lf", r, R);
//Calculate volume of torus
double volume = 2 * (M_PI * M_PI) * R * (r * r);
//Display volume
printf("\nVolume of torus : %lf\n", volume);
}
int main()
{
//Simple Case
torus_volume(3, 7);
torus_volume(4, 8);
torus_volume(6.2, 8.3);
return 0;
}``````

#### Output

``````Given Radius of r: 3.000000 Radius of R : 7.000000
Volume of torus : 1243.570155

Volume of torus : 2526.618727

Volume of torus : 6297.834047``````
``````// Java Program
// Find the volume of a torus
class Torus
{
//Calculate volume of a torus by given small and large radius
public void volume(double r, double R)
{
// Formula of torus volume
// 2 × π² × R × r²
// here r is radius of small circle
// R is radius of large circle
System.out.print("\nGiven Radius of small r: " + r + " Radius of large R : " + R + "");
//Calculate volume of torus
double volume = 2 * (Math.PI * Math.PI) * R * (r * r);
System.out.print("\nVolume of torus : " + volume + "\n");
}
public static void main(String[] args)
{
Torus torus = new Torus();
//Simple Case
torus.volume(3, 7);
torus.volume(4, 8);
torus.volume(6.2, 8.3);
}
}``````

#### Output

``````Given Radius of small r: 3.0 Radius of large R : 7.0
Volume of torus : 1243.570154537259

Given Radius of small r: 4.0 Radius of large R : 8.0
Volume of torus : 2526.6187266788756

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.834046752725``````
``````// C++ Program
// Find the volume of a torus
#include<iostream>
#include<math.h>

using namespace std;
class Torus
{
public:
//Calculate volume of a torus by given small and large radius
void volume(double r, double R)
{
cout << "\nGiven Radius of small r: " << r << " Radius of large R : " << R << "";
//Calculate volume of torus
double volume = 2 * (M_PI * M_PI) * R * (r * r);
cout << "\nVolume of torus : " << volume << "\n";
}
};
int main()
{
Torus torus ;
//Simple Case
torus.volume(3, 7);
torus.volume(4, 8);
torus.volume(6.2, 8.3);
return 0;
}``````

#### Output

``````Given Radius of small r: 3 Radius of large R : 7
Volume of torus : 1243.57

Given Radius of small r: 4 Radius of large R : 8
Volume of torus : 2526.62

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.83``````
``````// C# Program
// Find the volume of a torus
using System;
class Torus
{
//Calculate volume of a torus by given small and large radius
public void volume(double r, double R)
{
Console.Write("\nGiven Radius of small r: " + r + " Radius of large R : " + R + "");
//Calculate volume of torus
double volume = 2 * (Math.PI * Math.PI) * R * (r * r);
Console.Write("\nVolume of torus : " + volume + "\n");
}
public static void Main(String[] args)
{
Torus torus = new Torus();
//Simple Case
torus.volume(3, 7);
torus.volume(4, 8);
torus.volume(6.2, 8.3);
}
}``````

#### Output

``````Given Radius of small r: 3 Radius of large R : 7
Volume of torus : 1243.57015453726

Given Radius of small r: 4 Radius of large R : 8
Volume of torus : 2526.61872667888

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.83404675273``````
``````<?php
// Php Program
// Find the volume of a torus
class Torus
{
//Calculate volume of a torus by given small and large radius
public  function volume(\$r, \$R)
{
echo "\nGiven Radius of small r: ". \$r ." Radius of large R : ". \$R ."";
//Calculate volume of torus
\$volume = 2 * (M_PI * M_PI) * \$R * (\$r * \$r);
echo "\nVolume of torus : ". \$volume ."\n";
}
}

function main()
{
\$torus = new Torus();
//Simple Case
\$torus->volume(3, 7);
\$torus->volume(4, 8);
\$torus->volume(6.2, 8.3);
}
main();``````

#### Output

``````Given Radius of small r: 3 Radius of large R : 7
Volume of torus : 1243.5701545373

Given Radius of small r: 4 Radius of large R : 8
Volume of torus : 2526.6187266789

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.8340467527``````
``````// Node Js Program
// Find the volume of a torus
class Torus
{
//Calculate volume of a torus by given small and large radius
volume(r, R)
{
process.stdout.write("\nGiven Radius of small r: " + r + " Radius of large R : " + R + "");
//Calculate volume of torus
var volume = 2 * (Math.PI * Math.PI) * R * (r * r);
process.stdout.write("\nVolume of torus : " + volume + "\n");
}
}

function main()
{
var torus = new Torus();
//Simple Case
torus.volume(3, 7);
torus.volume(4, 8);
torus.volume(6.2, 8.3);
}
main();``````

#### Output

``````Given Radius of small r: 3 Radius of large R : 7
Volume of torus : 1243.570154537259

Given Radius of small r: 4 Radius of large R : 8
Volume of torus : 2526.6187266788756

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.834046752725``````
``````#  Python 3 Program
#  Find the volume of a torus
import math
class Torus :
# Calculate volume of a torus by given small and large radius
def volume(self, r, R) :
print("\nGiven Radius of small r: ", r ," Radius of large R : ", R ,"", end = "")
# Calculate volume of torus
volume = 2 * (math.pi * math.pi) * R * (r * r)
print("\nVolume of torus : ", volume ,"\n", end = "")

def main() :
torus = Torus()
# Simple Case
torus.volume(3, 7)
torus.volume(4, 8)
torus.volume(6.2, 8.3)

if __name__ == "__main__": main()``````

#### Output

``````Given Radius of small r:  3  Radius of large R :  7
Volume of torus :  1243.570154537259

Given Radius of small r:  4  Radius of large R :  8
Volume of torus :  2526.6187266788756

Given Radius of small r:  6.2  Radius of large R :  8.3
Volume of torus :  6297.834046752725``````
``````#  Ruby Program
#  Find the volume of a torus
class Torus

# Calculate volume of a torus by given small and large radius
def volume(s_r, l_r)

#  Formula of torus volume
#  2 × π² × R × r²
#  here r is radius of small circle
#  R is radius of large circle
print("\nGiven Radius of small r: ", s_r ," Radius of large R : ", l_r ,"")
# Calculate volume of torus
volume = 2 * (Math::PI * Math::PI) * l_r * (s_r * s_r)
print("\nVolume of torus : ", volume ,"\n")
end
end
def main()

torus = Torus.new()
# Simple Case
torus.volume(3, 7)
torus.volume(4, 8)
torus.volume(6.2, 8.3)
end
main()``````

#### Output

``````Given Radius of small r: 3 Radius of large R : 7
Volume of torus : 1243.570154537259

Given Radius of small r: 4 Radius of large R : 8
Volume of torus : 2526.6187266788756

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.834046752725
``````
``````// Scala Program
// Find the volume of a torus
class Torus
{
//Calculate volume of a torus by given small and large radius
def volume(r: Double, R: Double): Unit = {
// Formula of torus volume
// 2 × π² × R × r²
// here r is radius of small circle
// R is radius of large circle
print("\nGiven Radius of small r: " + r + " Radius of large R : " + R + "");
//Calculate volume of torus
var volume: Double = 2 * (Math.PI * Math.PI) * R * (r * r);
print("\nVolume of torus : " + volume + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var torus: Torus = new Torus();
//Simple Case
torus.volume(3, 7);
torus.volume(4, 8);
torus.volume(6.2, 8.3);
}
}``````

#### Output

``````Given Radius of small r: 3.0 Radius of large R : 7.0
Volume of torus : 1243.570154537259

Given Radius of small r: 4.0 Radius of large R : 8.0
Volume of torus : 2526.6187266788756

Given Radius of small r: 6.2 Radius of large R : 8.3
Volume of torus : 6297.834046752725``````
``````// Swift Program
// Find the volume of a torus
import Foundation
class Torus
{
//Calculate volume of a torus by given small and large radius
func volume(_ r: Double, _ R: Double)
{
print("\nGiven Radius of small r: ", r ," Radius of large R : ", R ,"", terminator: "");
//Calculate volume of torus
let volume: Double = 2 * (Double.pi * Double.pi) * R * (r * r);
print("\nVolume of torus : ", volume ,"\n", terminator: "");
}
}
func main()
{
let torus: Torus? = Torus();
//Simple Case
torus!.volume(3, 7);
torus!.volume(4, 8);
torus!.volume(6.2, 8.3);
}
main();``````

#### Output

``````Given Radius of small r:  3.0  Radius of large R :  7.0
Volume of torus :  1243.57015453726

Given Radius of small r:  4.0  Radius of large R :  8.0
Volume of torus :  2526.61872667888

Given Radius of small r:  6.2  Radius of large R :  8.3
Volume of torus :  6297.83404675273`````` ## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.