Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#을 사용하여 구의 부피와 표면적을 찾는 방법은 무엇입니까?

<시간/>

구의 부피와 표면적은 먼저 반지름 값으로 변수를 선언합니다.

int r = 15;

구체의 부피를 구하십시오.

// 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