+ 1
Someone who explains to me how it is resolved and why it is resolved like this?
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
29 ответов
- 2
Antonio , if radius is of integer type, you can do it this way.
https://code.sololearn.com/cwrG82Cm5iy9/?ref=app
+ 23
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;
radius = Double.Parse(Console.ReadLine());
double area = pi * (radius*radius);
Console.WriteLine(area);
}
}
}
+ 10
I've struggled a lot with this one too, I still don't understand it despite re-reading it over again for the last few days.
I'm getting tired of the replies that answer like: "Oh just do this, it's so simple."
Yes, it's simple To You. We're beginners, we don't understand what double.parse whatever even is especially since it's glossed over in the course.
Stop treating beginner coders like they should know what they're doing day one, they're here to learn, not be berated.
+ 5
Thank you but what is Double.Pars?
+ 2
Sorry, i am new, where i wrong?
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 = 25;
int(Area) = pi*double radius;
//your code goes here
Console.WriteLine(Area);
}
}
}
+ 2
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());
Console.WriteLine(radius * pi * radius);
}
}
}
+ 1
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;
double area;
radius = Convert.ToDouble(Console.ReadLine()
);
area = pi*radius*radius;
Console.WriteLine(area);
Console.ReadLine();
}
}
}
This is the code you are looking for.
Take your time and understand it if you don't go back to module 1 notes
+ 1
Circumference of a circle with two digits after comma (,) ;
function main() {
var r = parseInt(readLine(), 10)
var calcCirc = Math.PI* 2 *r
//the output
console.log(calcCirc.toFixed(2));
}
function calcCirc(){
return Math.PI* 2 *r
+ 1
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 = Double.Parse(Console.ReadLine());
double area;
area = pi*radius*radius;
Console.WriteLine(area);
}
}
}
0
Antonio , read the radius as input, declare the pi constant and assign the value of it. Then declare the area variable of double type perform the calculation. Print the result.
0
const double pi = 3.14; and double radius; were already present in the code
0
Antonio , changed it in the code.
0
Antonio , transforming the string input to double.
0
Antonio , it's mentioned in the description you gave that radius is read as an input.
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 = Double.Parse(Console.ReadLine());
double area = pi*radius*radius;
0
function main() {
var r = parseInt(readLine(), 10)
//the output
console.log(calcCirc(r).toFixed(2));
}
//complete the function
function main() {
var r = parseInt(readLine(), 10)
var calcCirc = Math.PI* 2 *r
//the output
console.log(calcCirc.toFixed(2));
}
function calcCirc(){
return Math.PI* 2 *r
}
Good Luck
0
I believe the convertion and the exponential (power of) parts are missing from the free lesson.
However, while I'm following this lesson I also follow the free c# lesson at www.w3schools.com at the same time and they do explain the convertions and more math operators like the exponentials (Math.Pow(number, exponential), etc...
so based on both lessons I came up with the code below which works.
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
/*user inputs are ALWAYS considered as strings
no matter what, strings and numbers cannot calculate,
therefore we need to get the user's input and convert
it to a double as shown below */
radius = Convert.ToDouble(Console.ReadLine());
/*after we converted user input (string to double) we can
then calculate the output just by writing out the formular.
pi * (radius * radius) also works */
Console.WriteLine(pi * (Math.Pow(radius, 2)));
}
}
}
Hope this helps
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;
radius = Convert.ToDouble(Console.ReadLine());
double a = pi * (radius * radius);
Console.WriteLine(a);
}
}
}
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;
radius = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(+pi*radius*radius);
//your code goes here
}
}
}
0
Only in the first test it compiles
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;
double radius2 = Math.Pow(radius, 2);
double total = pi * radius2;
Console.WriteLine(total);
}
}
}