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:38
-
Ejercicio:
The gravitational field of the Moon is approximately 17% of that on the Earth.
Write a program that calculates the weight of a man on the moon by a given weight W(as a floating-point number) on the Earth.
The weight W should be read from the console.
El código:
using System;
class Program
{
static void Main()
{
sbyte a = 31;
while(a < -30 || a > 30)
{
Console.WriteLine("Introduzca un número entero entre -30 y 30: ");
a = Convert.ToSByte(Console.ReadLine());
}
if(a % 2 == 0){
Console.WriteLine("El número: " + a + " es par");
}else{
Console.WriteLine("El número: " + a + " es impar");
}
}
}
Saludos.