如何使用 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP