- 2
Area of a circle
We are going to write a program that will calculate the area of ââa circle. The area enclosed by a circle of radius r is Ďr², where Ď (pi) is the constant ratio of the circumference of any circle to its diameter, and r is the radius. The given program declares a constant pi variable with a value of 3.14. Complete the program to take the radius as input, then calculate and output the area of the circle. Sample Input 5 Sample Output 78.5
4 Answers
+ 3
Hi Alexander, can you show us your attempts at solving the problem? It would give us better context to understand where you are stuck.
0
Hi hatsy,
My solution is below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
const double pi = 3.14;
double[] radius = {5,6.4,10};
double area;
int i =0;
double t = Convert.ToDouble(radius[i++]);
switch(t)
{
case 5:
area = pi
* (t * t);
Console.WriteLine(area);
break;
case 6.4:
area = pi
* (t * t);
Console.WriteLine(area);
break;
case 10:
area = pi
* (t * t);
Console.WriteLine(area);
- 1
Read the task description carefully:
"Complete the program to take the radius as input"