📜  查找圆周的程序

📅  最后修改于: 2021-04-27 23:41:10             🧑  作者: Mango

给定圆的半径,编写一个程序以查找其圆周。
例子 :

Input : 2
Output : Circumference = 12.566

Input : 8
Output : Circumference = 50.264

在一个圆中,位于圆边界内的点距其中心的距离相同。该距离称为半径。圆的周长可以简单地使用以下公式进行评估。

Circumference = 2*pi*r
where r is the radius of circle 
and value of pi = 3.1415.

C++
// CPP program to find circumference of circle
#include
using namespace std;
 
#define PI 3.1415
 
double circumference(double r)
{
    double cir = 2*PI*r;
    return cir;
}
 
// driver function
int main()
{
  double r = 5;
  cout << "Circumference = "
       << circumference(r);
  return 0;
}


Java
// Java program to find circumference of circle
import java.io.*;
 
class Geometry {
     
    // utility function
    static double circumference(double r){
 
        double PI = 3.1415;
        double cir = 2*PI*r;
        return cir;
    }
     
    // driver function
    public static void main (String[] args) {
 
        double r = 5;
        double result = Math.round(circumference(r) * 1000) / 1000.0;
        System.out.println("Circumference = "+ result);
    }
}
 
// This article is contributed by Chinmoy Lenka


Python3
# Python3 code to find
# circumference of circle
 
PI = 3.1415
 
# utility function
def circumference(r):
    return (2 * PI * r)
 
 
# driver function
print ('%.3f' % circumference(5))
 
# This code is contributed by Saloni Gupta


C#
// C# program to find circumference of circle
using System;
 
class GFG {
     
    // utility function
    static double circumference(double r){
 
        double PI = 3.1415;
        double cir = 2*PI*r;
        return cir;
    }
     
    // driver function
    public static void Main () {
 
        double r = 5;
        double result =
              Math.Round(circumference(r)
                        * 1000) / 1000.0;
                         
        Console.WriteLine("Circumference = "
                                  + result);
    }
}
 
// This article is contributed by anuj_67.


PHP


Javascript


输出 :

Circumference = 31.415