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 27 de Julio 2016, 14:30
-
Ejercicio resuelto de C#:
Multiplication sign
Description
Write a program that shows the sign (+, - or 0) of the product of three real numbers, without calculating it.
Use a sequence of if operators.
El código:
using System;
namespace MultiplicationSign {
class Program {
static void Main() {
double a = double.Parse(Console.ReadLine());
double b = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
double producto = a * b * c;
if(producto < 0) {
Console.WriteLine("-");
}else if(producto > 0) {
Console.WriteLine("+");
}else {
Console.WriteLine("0");
}
}
}
}
Saludos.