+ 11
Area of a circle in C#
Please help with how to do this?
11 Answers
+ 12
You need to declare area like double area since radius is also double. Also Convert.ToDouble() should be applied to Console.ReadLine() because what it does it to convert the input to double.
radius = Convert.ToDouble(Console.ReadLine());
double area = pi * radius * radius;
Console.WriteLine(area);
+ 8
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;
//your code goes here
radius = Convert.ToDouble(Console.ReadLine());
double area = pi * radius * radius;
Console.WriteLine(area);
}
}
}
+ 3
Oli, acá les dejo otra alternativa para resolverlo:
radius = Convert.ToDouble(Console.ReadLine());
// Get the exponent of radius
double exp = Math.Pow(radius, 2) * pi;
Console.WriteLine(exp);
0
Thanks for the help. Here is the code I have im not sure where im going wrong!
const double pi = 3.14;
double radius;
Console.Writeline("Enter Radius: ");
(Console.Readline());
area = Convert.ToDouble Math.PI * radius * radius;
Console.Writeline"Area of Circle: ");
Conesole.Readkey();
0
thanks so much for explaining, this makes sense!
0
I'm getting the first test case right, but I am not sure how to get the other two test case results in order to complete the mini project.
How do I execute all three area tests?
edit- I've figured my own question out. I need to first convert the radius input (which is found by using Console.Readline() to a double, and then using that to determine the value of the area before using Console.Writeline to declare the output.
test passed.
0
This may seem like a silly question but why do we need to convert the radius input to double if the radius was already declared a double? I just feel like its being declared twice.
0
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 = Convert.ToDouble(Console.ReadLine());
double area = pi * radius * radius;
Console.WriteLine(area);
}
}
}
We use Console.ReadLine() for input. This function means the user will type the input then use Enter to apply.
For emxample Console.ReadLine() and we type 5 then enter. The program will run like Console.ReadLine(5).
Convert.ToDouble will double the Console.ReadLine(5). This function will replace the 5^2 or 5*5
- 1
area = πr² = π. input here ²
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;
//your code goes here
radius = Convert.ToDouble(Console.ReadLine());
double area = pi * (radius * radius);
Console.WriteLine(area);
}
}
}
- 2
pi*radius*radius and you get the area.