Calculate volume and surface area of Torus - GeeksforGeeks

06 Sep, 2021
This article is about the surface and mathematical concept of a torus. A 3D shape made by revolving a small circle (radius r) along a line made by a bigger circle (radius R).  
Torus
Property:
It can be made by revolving a small circle (radius r) along a line made by a bigger circle (radius R).It is not a polyhedronIt has no vertices or edges
It can be made by revolving a small circle (radius r) along a line made by a bigger circle (radius R).
It is not a polyhedron
It has no vertices or edges
Surface Area The surface area of a Torus is given by the formula –
Surface Area = 4 × Pi^2 × R × r
Where r is the radius of the small circle and R is the radius of bigger circle and Pi is constant Pi=3.14159.  
Volume The volume of a cone is given by the formula –
Volume = 2 × Pi^2 × R × r^2
Where r is the radius of the small circle and R is the radius of bigger circle and Pi is constant Pi=3.14159.
Examples:
Input : r=3, R=7
Output :
     Volume: 1243.568195
     Surface: 829.045464
 
C++
C
Java
Python3
C#
PHP
Javascript
// C++ program to calculate volume// and surface area of Torus#include<bits/stdc++.h>using namespace std;  int main(){    // radius of inner circle    double r = 3;      // distance from origin to center of inner circle    // radius of black circle in figure    double R = 7;      // Value of Pi    float pi = (float)3.14159;    double Volume = 0;    Volume = 2 * pi * pi * R * r * r;    cout<<"Volume: "<<Volume<<endl;      double Surface = 4 * pi * pi * R * r;    cout<<"Surface: "<<Surface<<endl;}
// C program to calculate volume // and surface area of Torus#include <stdio.h>int main(){    // radius of inner circle    double r = 3;      // distance from origin to center of inner circle    // radius of black circle in figure    double R = 7;      // Value of Pi    float pi = (float)3.14159;    double Volume = 0;    Volume = 2 * pi * pi * R * r * r;    printf("Volume: %f", Volume);      double Surface = 4 * pi * pi * R * r;    printf("\nSurface: %f", Surface);}
// Java program to calculate volume // and surface area of Torusclass Test {      public static void main(String args[])    {          // radius of inner circle        double r = 3;          // distance from origin to center of inner circle        // radius of black circle in figure        double R = 7;          // Value of Pi        float pi = (float)3.14159;        double Volume = 0;        Volume = 2 * pi * pi * R * r * r;        System.out.printf("Volume: %f", Volume);          double Surface = 4 * pi * pi * R * r;        System.out.printf("\nSurface: %f", Surface);    }}
# Python3 program to calculate volume# and surface area of Torus# radius of inner circler = 3  # distance from origin to center of inner circle# radius of black circle in figureR = 7  # Value of Pipi = 3.14159Volume = (float)(2 * pi * pi * R * r * r);print("Volume: ", Volume);Surface = (float)(4 * pi * pi * R * r);print("Surface: ", Surface);
// C# program to calculate volume // and surface area of Torus using System;  class GFG {       // Driver Codepublic static void Main() {       // radius of inner circle     double r = 3;       // distance from origin to center     // of inner circle radius of black    // circle in figure     double R = 7;       // Value of Pi     float pi = (float)3.14159;     double Volume = 0;     Volume = 2 * pi * pi * R * r * r;     Console.WriteLine("Volume: {0}", Volume);       double Surface = 4 * pi * pi * R * r;     Console.WriteLine("Surface: {0}", Surface); } }   // This code is contributed by Soumik
<?php// PHP program to calculate volume // and surface area of Torus   // radius of inner circle $r = 3;   // distance from origin to center // of inner circle radius of black// circle in figure $R = 7;   // Value of Pi $pi = (float)3.14159; $Volume = 0; $Volume = 2 * $pi * $pi * $R * $r * $r;   echo "Volume: ", $Volume, "\n";   $Surface = 4 * $pi * $pi * $R * $r;   echo "Surface: ", $Surface, "\n";       // This code is contributed by ajit?>
<script>  // Javascript program to calculate volume// and surface area of Torus  // radius of inner circlevar r = 3;  // distance from origin to center of inner circle// radius of black circle in figurevar R = 7;  // Value of Pivar pi = 3.14159;var Volume = 0;Volume = 2 * pi * pi * R * r * r;document.write("Volume: " + Volume + "<br>");  var Surface = 4 * pi * pi * R * r;document.write("Surface: " + Surface);  </script>
Volume: 1243.568195
Surface: 829.045464
 
SURENDRA_GANGWAR
SoumikMondal
jit_t
rrrtnx
rs1686740
area-volume-programs
Technical Scripter 2018
Mathematical
Technical Scripter
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Find all factors of a natural number | Set 1
Check if a number is Palindrome
Program to print prime numbers from 1 to N.
Program to add two binary strings
Program to multiply two matrices
Fizz Buzz Implementation
Find pair with maximum GCD in an array
Find Union and Intersection of two unsorted arrays
Count all possible paths from top left to bottom right of a mXn matrix
Count ways to reach the n'th stair