Last active
June 25, 2019 20:37
-
-
Save celiosouza2013/e7630737197da89eb62e645486f11b48 to your computer and use it in GitHub Desktop.
Execício área triangulo utilizando classes, atributos e métodos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Criando Classe | |
using System; | |
namespace Course | |
{ | |
class Triangulo | |
{ | |
public double A; | |
public double B; | |
public double C; | |
public double Area() | |
{ | |
double p = (A + B + C) / 2.0; | |
return Math.Sqrt(p * (p - A) * (p - B) * (p - C)); | |
} | |
} | |
} | |
//_________________________________________________________ | |
using System; | |
using System.Globalization; | |
namespace Course | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Triangulo x, y; | |
x = new Triangulo(); | |
y = new Triangulo(); | |
Console.WriteLine("Entre com as medidas do triângulo X:"); | |
x.A = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
x.B = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
x.C = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
Console.WriteLine("Entre com as medidas do triângulo Y:"); | |
y.A = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
y.B = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
y.C = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
double areaX = x.Area(); | |
double areaY = y.Area(); | |
Console.WriteLine("Área de X = " + areaX.ToString("F4", CultureInfo.InvariantCulture)); | |
Console.WriteLine("Área de Y = " + areaY.ToString("F4", CultureInfo.InvariantCulture)); | |
if (areaX > areaY) | |
{ | |
Console.WriteLine("Maior área: X"); | |
} | |
else | |
{ | |
Console.WriteLine("Maior área: Y"); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey you, I made some changes in your code in my fork, chek it out:
https://gist.github.com/robsonalves/df50208dbc4d6cd435859c048c99e18c