Advertisement
son4etyyy

SurfaceOfTriangle

Jan 26th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _4.SurfaceOfTriangle
  8. {
  9.     /*Write methods that calculate the surface of a triangle by given:
  10. Side and an altitude to it; Three sides; Two sides and an angle between them. Use System.Math.*/
  11.     class Program
  12.     {
  13.         static void SOfTriangle1(int a, int ha)
  14.         {
  15.             double s = a * ha / 2.0;
  16.             Console.WriteLine("The surface of the triangle is {0}", s);
  17.         }
  18.         static void SOfTriangle2(int a, int b, int c)
  19.         {
  20.             double p = (a + b + c) / 2.0;
  21.             double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
  22.             Console.WriteLine("The surface of the triangle is {0}", s);//neto4nost (5,2,6)
  23.         }
  24.         static void SOfTriangle3(int a, int b, double c)
  25.         {
  26.             double angle = Math.PI * c / 180.0;
  27.             double s = a * b * Math.Sin(angle) / 2;
  28.             Console.WriteLine("The surface of the triangle is {0}", s);
  29.         }
  30.  
  31.         static void Main(string[] args)
  32.         {
  33.             Console.WriteLine("What do we have? \n a)Side and an altitude to it \n b)Three sides \n c)Two sides and an angle between them");
  34.             string choise = Console.ReadLine();
  35.             if (choise == "a")
  36.             {
  37.                 Console.WriteLine("the side is:");
  38.                 int a = int.Parse(Console.ReadLine());
  39.                 Console.WriteLine("the altitude to it is:");
  40.                 int ha = int.Parse(Console.ReadLine());
  41.                 SOfTriangle1(a,ha);
  42.             }
  43.             else if (choise == "b")
  44.             {
  45.                 Console.WriteLine("the first side is:");
  46.                 int a = int.Parse(Console.ReadLine());
  47.                 Console.WriteLine("the second side is:");
  48.                 int b = int.Parse(Console.ReadLine());
  49.                 Console.WriteLine("the third side is:");
  50.                 int c = int.Parse(Console.ReadLine());
  51.                 SOfTriangle2(a,b,c);
  52.             }
  53.             else if (choise == "c")
  54.             {
  55.                 Console.WriteLine("the first side is:");
  56.                 int a = int.Parse(Console.ReadLine());
  57.                 Console.WriteLine("the second side is:");
  58.                 int b = int.Parse(Console.ReadLine());
  59.                 Console.WriteLine("the angle between them is:");
  60.                 double c = double.Parse(Console.ReadLine());
  61.                 SOfTriangle3(a, b, c);
  62.             }
  63.             else Console.WriteLine(" Invalid option!");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement