Foros aprenderaprogramar.com
Aprender a programar => C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más => Mensaje iniciado por: Dimitar Stefanov en 18 de Julio 2016, 20:51
-
Ejercicio:
Write an expression that calculates trapezoid's area by given sides a and b and height h. The three values should be read from the console in the order shown below. All three value will be floating-point numbers.
El código:
using System;
class Program {
static void Main() {
float ladoA;
float ladoB;
float altura;
Console.Write("Introduce el lado A: ");
ladoA = float.Parse(Console.ReadLine());
Console.Write("Introduce el lado B: ");
ladoB = float.Parse(Console.ReadLine());
Console.Write("Introduce la altura: ");
altura = float.Parse(Console.ReadLine());
float area = (float)(((ladoA+ladoB)*altura)/2.0);
Console.WriteLine("El área del trapecio es: "+area.ToString("f7"));
}
}
Saludos.