C# :: Aufgabe #261 :: Lösung #1
5 Lösungen
#261
Alle Winkel von einem Dreieck ausrechnen...
Fortgeschrittener - C#
von maxi72501
- 06.05.2019 um 15:01 Uhr
Gegeben sind alle Koordinaten. Die Punkte A und B gibt der Benutzer ein und die C Koordinate ist der Koordinaten Ursprung (0, 0).
Anhand der Seiten soll der Flächeninhalt und alle Winkel berechnet werden.
Anhand der Seiten soll der Flächeninhalt und alle Winkel berechnet werden.
#1
von Kotgreifer (1100 Punkte)
- 08.05.2019 um 16:12 Uhr
using System;
namespace DreieckRechner
{
class Program
{
static void Main(string[] args)
{
Console.Write("A x: ");
double Ax;
double.TryParse(Console.ReadLine(), out Ax);
Console.Write("A y: ");
double Ay;
double.TryParse(Console.ReadLine(), out Ay);
Console.Write("B x: ");
double Bx;
double.TryParse(Console.ReadLine(), out Bx);
Console.Write("B y: ");
double By;
double.TryParse(Console.ReadLine(), out By);
Console.Write("C x: ");
double Cx;
double.TryParse(Console.ReadLine(), out Cx);
Console.Write("C y: ");
double Cy;
double.TryParse(Console.ReadLine(), out Cy);
double a = Math.Sqrt(Math.Pow(Bx - Cx, 2) + Math.Pow(By - Cy, 2));
double b = Math.Sqrt(Math.Pow(Ax - Cx, 2) + Math.Pow(Ay - Cy, 2));
double c = Math.Sqrt(Math.Pow(Ax - Bx, 2) + Math.Pow(Ay - By, 2));
a = Math.Round(a, 3);
b = Math.Round(b, 3);
c = Math.Round(c, 3);
Console.WriteLine("\n-------------------\nLängen: \na= " + a + " cm \nb= " + b + " cm \nc= " + c + " cm\n-------------------\n");
double winkelA = Math.Round((180 / Math.PI) * Math.Acos((Math.Pow(b, 2) + Math.Pow(c, 2) - Math.Pow(a, 2)) / (2 * b * c)), 3);
double winkelB = Math.Round((180 / Math.PI) * Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)), 3);
double winkelC = 180 - winkelA - winkelB;
Console.WriteLine("\n-------------------\nWinkel: \nAplpha= " + winkelA + " Grad \nBeta= " +winkelB +" Grad \nGamma= "+winkelC+ " Grad\n-------------------\n");
double u = a + b + c;
double fläche = Math.Round((Math.Sqrt(u / 2 * (u / 2 - a) * (u / 2 - b) * (u / 2 - c))), 3);
Console.WriteLine("\n-------------------\nUmfang= " + u + " cm\nFläche= " + fläche+ " cm*2\n-------------------");
Console.Read();
}
}
}
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1
