如何使用 C# 找到球體的體積和表面積?


對於球體的體積和表面積,首先宣告一個變數(值為半徑)。

int r = 15;

獲取球體的體積 f。

// calculating volume of sphere
cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;

現在,球體的表面積計算如下 −

cal_area = 4 * (22 / 7) * r * r;

讓我們看看完整的程式碼 −

示例

 線上演示

using System;
using System.Collections.Generic;

public class Demo {
   public static void Main(string[] args) {
      double cal_area, cal_volume, r;
      // radius
      r = 15;

      // calculating area of sphere
      cal_area = 4 * (22 / 7) * r * r;

      // calculating volume of sphere
      cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;

      Console.WriteLine("Area of Sphere: " + cal_area);
      Console.WriteLine("Volume of Sphere: " + cal_volume);
   }
}

輸出

Area of Sphere: 2700
Volume of Sphere: 13500

更新於: 22-6 月-2020

273 閱讀量

開啟您的 職業生涯

透過完成課程獲得認證

入門
廣告
© . All rights reserved.