+ 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

14th Dec 2020, 7:24 PM
Antonio
Antonio - avatar
29 Respuestas
- 2
Antonio , if radius is of integer type, you can do it this way. https://code.sololearn.com/cwrG82Cm5iy9/?ref=app
14th Dec 2020, 7:52 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 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); } } }
8th Feb 2021, 11:38 AM
Ing Carlos José Meran
Ing Carlos José Meran - avatar
+ 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.
19th Apr 2021, 8:06 AM
Martin Bodger
Martin Bodger - avatar
+ 5
Thank you but what is Double.Pars?
14th Dec 2020, 8:01 PM
Antonio
Antonio - avatar
+ 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); } } }
14th Dec 2020, 7:49 PM
Antonio
Antonio - avatar
+ 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); } } }
18th Aug 2021, 5:09 AM
Robin Vogel
+ 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
12th Mar 2021, 5:44 AM
Sagar Sir
Sagar Sir - avatar
+ 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
30th Dec 2021, 4:36 AM
Ali Simsek
+ 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); } } }
14th Feb 2023, 12:59 PM
Guy Martial KEYOU
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.
14th Dec 2020, 7:39 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
const double pi = 3.14; and double radius; were already present in the code
14th Dec 2020, 7:53 PM
Antonio
Antonio - avatar
0
Antonio , changed it in the code.
14th Dec 2020, 7:56 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Antonio , transforming the string input to double.
14th Dec 2020, 8:01 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Antonio , it's mentioned in the description you gave that radius is read as an input.
14th Dec 2020, 8:07 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
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;
14th Dec 2020, 11:40 PM
SeyedAmirHossein Naghibi
SeyedAmirHossein Naghibi - avatar
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
25th Jan 2022, 8:36 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
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
4th Feb 2022, 11:28 AM
Taukoriri Meita
Taukoriri Meita - avatar
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); } } }
19th Apr 2022, 2:32 PM
Infinie Ty
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 } } }
26th Jun 2022, 10:17 AM
Vivek Padia
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); } } }
5th Jul 2022, 1:32 AM
Jorge Garzón
Jorge Garzón - avatar