Area of a circle | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

30th Oct 2021, 1:20 AM
Alexander Kwesi
Alexander Kwesi - avatar
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.
30th Oct 2021, 3:04 AM
Hatsy Rei
Hatsy Rei - avatar
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);
30th Oct 2021, 4:22 PM
Alexander Kwesi
Alexander Kwesi - avatar
- 1
Read the task description carefully: "Complete the program to take the radius as input"
30th Oct 2021, 4:39 PM
Simon Sauter
Simon Sauter - avatar