desislava_topuzakova

7. Лица на фигури

Nov 20th, 2021
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _07._Area_of_Figures
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string type = Console.ReadLine();
  10.             double area = 0; //лицето на фигурата
  11.             //проверка за вид: square, rectangle, triangle, circle
  12.             if (type == "square")
  13.             {
  14.                 //квадрат
  15.                 double a = double.Parse(Console.ReadLine());
  16.                 area = a * a;
  17.             }
  18.             else if (type == "rectangle")
  19.             {
  20.                 //правоъгълник
  21.                 double width = double.Parse(Console.ReadLine());
  22.                 double length = double.Parse(Console.ReadLine());
  23.                 area = width * length;
  24.             }
  25.             else if (type == "triangle")
  26.             {
  27.                 //триъгълник
  28.                 double b = double.Parse(Console.ReadLine());
  29.                 double h = double.Parse(Console.ReadLine());
  30.                 area = b * h / 2;
  31.             }
  32.             else if (type == "circle")
  33.             {
  34.                 //кръг
  35.                 double r = double.Parse(Console.ReadLine());
  36.                 area = Math.PI * r * r;
  37.             }
  38.  
  39.  
  40.             Console.WriteLine($"{area:F3}");
  41.  
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment