lmarkov

Perimeter And Area Of A Circle

Nov 30th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. /*
  2.  * Write a program that reads the radius r of a circle and prints its perimeter and area.
  3. */
  4.  
  5. using System;
  6.  
  7. class PerimeterAndAreaOfACircle
  8. {
  9.     static void Main()
  10.     {
  11.         double radius, perimeter, area;
  12.  
  13.         string invalidInput = "Invalid input! Please enter value between 0 and " + double.MaxValue + "!\r\n";
  14.  
  15.         Console.WriteLine("enter value for radius of a circle r = ");
  16.         while (!(double.TryParse(Console.ReadLine(), out radius) && radius > 0 && radius <= double.MaxValue))
  17.         {
  18.             Console.WriteLine(invalidInput + "\r\nenter value for radius of a circle r = ");
  19.         }
  20.         checked { perimeter = 2 * Math.PI * radius; }
  21.         checked { area = Math.PI * (radius * radius); }        
  22.  
  23.         Console.WriteLine("\r\nResults:\r\nperimeter = {0}\r\narea = {1}\r\n", perimeter, area);
  24.         Main();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment