Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Write a program that reads the radius r of a circle and prints its perimeter and area.
- */
- using System;
- class PerimeterAndAreaOfACircle
- {
- static void Main()
- {
- double radius, perimeter, area;
- string invalidInput = "Invalid input! Please enter value between 0 and " + double.MaxValue + "!\r\n";
- Console.WriteLine("enter value for radius of a circle r = ");
- while (!(double.TryParse(Console.ReadLine(), out radius) && radius > 0 && radius <= double.MaxValue))
- {
- Console.WriteLine(invalidInput + "\r\nenter value for radius of a circle r = ");
- }
- checked { perimeter = 2 * Math.PI * radius; }
- checked { area = Math.PI * (radius * radius); }
- Console.WriteLine("\r\nResults:\r\nperimeter = {0}\r\narea = {1}\r\n", perimeter, area);
- Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment