saludos :D bueno tengo un problema hice este programa para diferencia enter 2 numeros cual es el mayor pero entre 3 no se que tengo que usar exactamente :-\ espero me puedan ayudar de nuevo gracias :P
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//variables
int n1;
int n2;
//Asignacion de valores alas variables
n1 = System.Int32.Parse(textBox1.Text);
n2 = System.Int32.Parse(textBox2.Text);
//condicion
if (n1 > n2)
textBox4.Text = n1.ToString();
else
textBox4.Text = n2.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox4.Text = "";
textBox1.Focus();
}
}
}
simple, a lo manual agregás esta funcion ...
private int Max(int a,int b){return a>b?a:b;}
entonces es cuestión de ...
int _ret = Max(n1,n2);
textBox4.Text = Max(_ret,n3).ToString();
max(max(n1,n2),n3) también es válido si querés achicar el code ...
y te quedás con el mayor ^^
Alex~
muchas gracias por responder :) pero solo puedo usar if anidados segun tengo que usar ese metodo :P no se si se puede hacer con if anidados
Si lo quieres hacer de la forma deficil usaras if anidados. Lo ideal seria que uses un vector y para ordenar uses el metodo de la BURBUJA.
Un saludo.
ohh gracias ya habia escuchado algo sobre ese metodo echare un ojo ;D
saludos
ya me salio gracias por su ayuda :D
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace diferenciade3numeroscualesmayor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Declaracion de variables
int m, n1, n2, n3;
//variables
n1 = System.Int32.Parse(textBox1.Text);
n2 = System.Int32.Parse(textBox2.Text);
n3 = System.Int32.Parse(textBox3.Text);
//condiciones
if (n1 > n2 && n1 > n3)
{
m = n1;
textBox4.Text = m.ToString();
}
else
{
if (n2 > n1 && n2 > n3)
{
m = n2;
textBox4.Text = m.ToString();
}
else
{
m = n3;
textBox4.Text = m.ToString();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
}
}
}