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:22

Título: C# ejemplo condicional if Cambiar valores variables con condiciones mayor menor
Publicado por: Dimitar Stefanov en 27 de Julio 2016, 14:22
Ejercicio resuelto:

Citar
Exchange numbers
Description

Write a program that reads two double values from the console A and B, stores them in variables and exchanges their values if the first one is greater than the second one. Use an if-statement. As a result print the values of the variables A and B, separated by a space.

El código:

Código: [Seleccionar]
using System;

namespace ExchangeNumbers {
class Program {
static void Main() {

double a = double.Parse(Console.ReadLine());
double b = double.Parse(Console.ReadLine());
double aux;

if(a > b) {
aux = a;
a = b;
b = aux;
}

Console.WriteLine("{0} {1}", a, b);
}
}
}

Saludos