# Find the surface area of a torus

Here given code implementation process.

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

#include <math.h>

//Calculate surface area of a torus by given small and large radius
void torus_surface_area(double r, double R)
{
// Formula of torus area
// 4 × π² × 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 surface area of torus
double area = 4 * (M_PI * M_PI) * R * r;
//Display surface area
printf("\nSurface area of torus : %lf\n", area);
}
int main()
{
//Simple Case
torus_surface_area(3, 9);
torus_surface_area(5, 8);
torus_surface_area(6.2, 8.3);
return 0;
}``````

#### Output

``````Given Radius of r: 3.000000 Radius of R : 9.000000
Surface area of torus : 1065.917275

Surface area of torus : 1579.136704

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

#### Output

``````Given Radius of r: 3.0 Radius of R : 9.0
Surface area of torus : 1065.9172753176508

Surface area of torus : 1579.1367041742974

Surface area of torus : 2031.5593699202338``````
``````// C++ Program
// Find the surface area of a torus
#include<iostream>
#include<math.h>

using namespace std;
class Torus
{
public:
//Calculate surface area of a torus by given small and large radius
void surface_area(double r, double R)
{
cout << "\nGiven Radius of r: " << r << " Radius of R : " << R << " ";
// Formula of torus area
// 4 × π² × R × r
// here r is radius of small circle
// R is radius of large circle
//Calculate surface area of torus
double area = 4 * (M_PI * M_PI) * R * r;
cout << "\nSurface area of torus : " << area << "\n";
}
};
int main()
{
Torus torus;
//Simple Case
torus.surface_area(3, 9);
torus.surface_area(5, 8);
torus.surface_area(6.2, 8.3);
return 0;
}``````

#### Output

``````Given Radius of r: 3 Radius of R : 9
Surface area of torus : 1065.92

Surface area of torus : 1579.14

Surface area of torus : 2031.56``````
``````// C# Program
// Find the surface area of a torus
using System;
class Torus
{
//Calculate surface area of a torus by given small and large radius
public void surface_area(double r, double R)
{
Console.Write("\nGiven Radius of r: " + r + " Radius of R : " + R + " ");
// Formula of torus area
// 4 × π² × R × r
// here r is radius of small circle
// R is radius of large circle
//Calculate surface area of torus
double area = 4 * (Math.PI * Math.PI) * R * r;
Console.Write("\nSurface area of torus : " + area + "\n");
}
public static void Main(String[] args)
{
Torus torus = new Torus();
//Simple Case
torus.surface_area(3, 9);
torus.surface_area(5, 8);
torus.surface_area(6.2, 8.3);
}
}``````

#### Output

``````Given Radius of r: 3 Radius of R : 9
Surface area of torus : 1065.91727531765

Surface area of torus : 1579.1367041743

Surface area of torus : 2031.55936992023``````
``````<?php
// Php Program
// Find the surface area of a torus
class Torus
{
//Calculate surface area of a torus by given small and large radius
public	function surface_area(\$r, \$R)
{
echo "\nGiven Radius of r: ". \$r ." Radius of R : ". \$R ." ";
// Formula of torus area
// 4 × π² × R × r
// here r is radius of small circle
// R is radius of large circle
//Calculate surface area of torus
\$area = 4 * (M_PI * M_PI) * \$R * \$r;
echo "\nSurface area of torus : ". \$area ."\n";
}
}

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

#### Output

``````Given Radius of r: 3 Radius of R : 9
Surface area of torus : 1065.9172753177

Surface area of torus : 1579.1367041743

Surface area of torus : 2031.5593699202``````
``````#  Python 3 Program
#  Find the surface area of a torus
import math
class Torus :
# Calculate surface area of a torus by given small and large radius
def surface_area(self, r, R) :
print("\nGiven Radius of r: ", r ," Radius of R : ", R ," ", end = "")
#  Formula of torus area
#  4 × π² × R × r
#  here r is radius of small circle
#  R is radius of large circle
# Calculate surface area of torus
area = 4 * (math.pi * math.pi) * R * r
print("\nSurface area of torus : ", area ,"\n", end = "")

def main() :
torus = Torus()
# Simple Case
torus.surface_area(3, 9)
torus.surface_area(5, 8)
torus.surface_area(6.2, 8.3)

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

#### Output

``````Given Radius of r:  3  Radius of R :  9
Surface area of torus :  1065.9172753176508

Surface area of torus :  1579.1367041742974

Surface area of torus :  2031.5593699202338``````
``````#  Ruby Program
#  Find the surface area of a torus
class Torus

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

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

torus = Torus.new()
# Simple Case
torus.surface_area(3, 9)
torus.surface_area(5, 8)
torus.surface_area(6.2, 8.3)
end
main()``````

#### Output

``````Given Radius of small r: 3 Radius of large R : 9
Surface area of torus : 1065.9172753176508

Given Radius of small r: 5 Radius of large R : 8
Surface area of torus : 1579.1367041742974

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

#### Output

``````Given Radius of r: 3.0 Radius of R : 9.0
Surface area of torus : 1065.9172753176508

Surface area of torus : 1579.1367041742974

Surface area of torus : 2031.5593699202338``````
``````import Foundation
// Swift Program
// Find the surface area of a torus
class Torus
{
//Calculate surface area of a torus by given small and large radius
func surface_area(_ r: Double, _ R: Double)
{
print("\nGiven Radius of r: ", r ," Radius of R : ", R ," ", terminator: "");
// Formula of torus area
// 4 × π² × R × r
// here r is radius of small circle
// R is radius of large circle
//Calculate surface area of torus
let area: Double = 4 * (Double.pi * Double.pi) * R * r;
print("\nSurface area of torus : ", area ,"\n", terminator: "");
}
}
func main()
{
let torus: Torus? = Torus();
//Simple Case
torus!.surface_area(3, 9);
torus!.surface_area(5, 8);
torus!.surface_area(6.2, 8.3);
}
main();``````

#### Output

``````Given Radius of r:  3.0  Radius of R :  9.0
Surface area of torus :  1065.91727531765

Surface area of torus :  1579.1367041743

Surface area of torus :  2031.55936992023`````` ## 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.