Can some one please help me to solve this one? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can some one please help me to solve this one?

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

25th Sep 2021, 11:30 AM
Tim Tam
14 Answers
+ 2
Please show your attempt...So we can help you :)
25th Sep 2021, 11:46 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 4
Tim Tam follow these steps: 1. Take input into the variable radius, using Console.ReadLine() 2. Create a variable, (suppose area for example.) 3. Calculate area of circle by the given formula: area = pi * radius * radius; 5. Print the area using : Console.WriteLine(area); And still if you're unable to solve the challenge, kindly revisit on previous chapters. Happy Coding :)
25th Sep 2021, 12:28 PM
Rupali Haldiya
Rupali Haldiya - avatar
25th Sep 2021, 2:40 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 3
const double pi = 3.14; double radius = Convert.ToDouble(Console.ReadLine()); double area = pi*radius*radius; Console.WriteLine(area);
25th Sep 2021, 2:44 PM
SoloProg
SoloProg - 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 = Convert.ToDouble(Console.ReadLine()); // For all test cases double area = pi*radius*radius; Console.WriteLine(area); } } }
26th Sep 2021, 12:20 AM
SoloProg
SoloProg - avatar
+ 2
Because we have a decimal (pi) so the result must be decimal.
4th Oct 2021, 3:31 PM
SoloProg
SoloProg - avatar
+ 1
Thank you
25th Sep 2021, 12:13 PM
Tim Tam
+ 1
https://code.sololearn.com/cvHtMNlx0Kkt double r = Convert.ToDouble(Console.ReadLine()); double a = Math.PI * Math.Pow(r, 2.0); Console.WriteLine(Math.Round(a, 1)); // Keep learning & happy coding :D
25th Sep 2021, 12:34 PM
SoloProg
SoloProg - avatar
+ 1
Thank you so much guys😍😍😍
25th Sep 2021, 2:01 PM
Tim Tam
+ 1
Hi SoloProg, Because the method you did I haven't learned so I tried to combine you and Rupali together but still something wrong, Can someone help me to fix it 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 = 5; Convert.ToDouble(Console.ReadLine(area)); area = pi*radius*radius; Console.WriteLine(area); //your code goes here } } }
25th Sep 2021, 2:33 PM
Tim Tam
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; //your code goes here } } }
25th Sep 2021, 12:13 PM
Tim Tam
0
Yay I got it guys Thank you so much, Another thing is testcase number is done but in the test case number 2 still show the results of the test case number input 5 and out put 78.5, Just want to ask how to separate 2 test case or I mean I can have another input for radius like radius = 6.4 Hope you guy understand what I am trying to say😅
25th Sep 2021, 10:59 PM
Tim Tam
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 = 5; Convert.ToDouble(Console.ReadLine()); double area = pi*radius*radius; Console.WriteLine(area); //your code goes here } } } { static void Main(string[] args) { const double pi = 3.14; double radius = 6.4; Convert.ToDouble(Console.ReadLine()); double area = pi*radius*radius; Console.WriteLine(area); //your code goes here } } }
25th Sep 2021, 11:04 PM
Tim Tam
0
the Radius is not meant to be named twice and because you're radius is a while number it's not a double its a whole number meaning you should equal it to an int if you want to name your area variable a double do cause the answer will have a , after it meaning answer could be 2.2 example only.not answer hope it helps
4th Oct 2021, 6:41 AM
Ashley Lewis
Ashley Lewis - avatar