ALGORITMO PARA ORDENAR 3 NÚMEROS

Categoría de Estructura Condicional Anidada


Ordenar 3 numeros de forma ascendente y descendente en pseint

💻 Hacer un programa que lea tres números enteros y los muestre ordenados de mayor a menor y de menor a mayor (de forma ascendente y descendente).


Análisis :

Lo primero seria ordenar por descarte:
Por ejemplo: Si N1 > N2 y N1 > N3, sabemos que N1 es el mayor, por lo tanto faltaría preguntar si N2 > N3, si se da el caso que N2 es mayor que N3 fácil mente se sabe que : N1 es mayor, N2 es intermedio y N3 es el menor y se imprimen en ese orden.


ANÁLISIS DEL CÓDIGO

VARIABLES ENTRADA :
N1 = Guarda primer valor.
N2 = Guarda segundo valor.
N3 = Guarda tercer valor.
P = En orden descendente es el primer múmero.
S = Muestra el número intermedio.
T = En orden ascendente es el último número.

INGRESO : Se ingresan los 3 números (N1, N2, N3)
PROCESO : Compara cada número para obtener el orden de los tres números.
SALIDA : Muestra los números en orden descendente y ascendente.


Algoritmo en pseint que muestra números ordenados de mayor a menor y de menor a mayor PSeInt Estricto : DESCARGA EL CÓDIGO

algoritmo que calcule el IGV

Algoritmo en pseint - short youtube
Algoritmo programacion_work
    Definir N1, N2, N3, S, T, P como Entero;
    Escribir "INGRESE 3 NÚMEROS Y MUESTRE LOS VALORES ORDENADOS.";
    Escribir " ";
    Escribir Sin Saltar "Número 01 : ";
    Leer N1;
    Escribir Sin Saltar "Número 02 : ";
    Leer N2;
    Escribir Sin Saltar "Número 03 : ";
    Leer N3;
    Si (N1 > N2) Y (N1 > N3) Entonces
        P <- N1;
        Si N2 > N3 Entonces
            S <- N2;
            T <- N3;
        SiNo
            S <- N3;
            T <- N2;
        FinSi
    SiNo
        Si N2 > N3 Entonces
            P <- N2;
            Si N1 > N3 Entonces
                S <- N1;
                T <- N3;
            SiNo
                S <- N3;
                T <- N1;
            FinSi
        SiNo
            P <- N3;
            Si N1 > N2 Entonces
                S <- N1;
                T <- N2;
            SiNo
                S <- N2;
                T <- N1;
            FinSi
        FinSi
    FinSi
    Escribir " ";
    Escribir "Descendente : ", P, " - ", S, " - ", T;
    Escribir "Ascendente : ", T, " - ", S, " - ", P;
FinAlgoritmo
Algoritmo en pseint que muestra números ordenados de mayor a menor y de menor a mayor

código en python que muestra tres números ordenados Python :

print("ORDENAR 3 NÚMEROS INGRESADOS.")
n1 = int(input("Ingrese Número 01 : "))
n2 = int(input("Ingrese Número 02 : "))
n3 = int(input("Ingrese Número 03 : "))
if (n1 > n2) and (n1 > n3):
    p = n1
    if n2 > n3:
        s = n2
        t = n3
    else:
        s = n3
        t = n2
elif n2 > n3:
    p = n2
    if n1 > n3:
        s = n1
        t = n3
    else:
        s = n3
        t = n1
else:
    p = n3
    if n1 > n2:
        s = n1
        t = n2
    else:
        s = n2
        t = n1
print("Descendente : ", p, " - ", s, " - ", t)
print("Ascendente  : ", t, " - ", s, " - ", p)

código en Lenguaje C que muestre de forma ascendente 3 números Lenguaje C :

#include<stdio.h>
int main() {
    int n1, n2, n3, p,s, t;
    printf("09. ORDENAMIENTO DE NÚMEROS.\n\n");           
    printf("Ingrese Número 01 : ");
    scanf("%i",&n1);
    printf("Ingrese Número 02 : ");
    scanf("%i",&n2);
    printf("Ingrese Número 03 : ");
    scanf("%i",&n3);
    if ((n1>n2) && (n1>n3)) {
        p = n1;
        if (n2>n3) {
            s = n2; t = n3;
        } else {
            s = n3; t = n2;
        }
    } else {
        if (n2>n3) {
            p = n2;
            if (n1>n3) {
                s = n1; t = n3;
            } else {
                s = n3; t = n1;
            }
        } else {
            p = n3;
            if (n1>n2) {
                s = n1; t = n2;
            } else {
                s = n2; t = n1;
            }
        }
    }
    printf("\nDescendente : %i-%i-%i\n",p,s,t);
    printf("Ascendente  : %i-%i-%i\n",t,s,p);
    return 0;
}

código en Dev C++ dónde se ordene 3 números de mayor a menor Dev C++ :

#include<iostream>
using namespace std;
int main() {
    int n1, n2, n3, p,s, t;
    cout << "09. ORDENAMIENTO DE NÚMEROS.\n\n";
    cout << "Ingrese Número 01 : ";
    cin >> n1;
    cout << "Ingrese Número 02 : ";
    cin >> n2;
    cout << "Ingrese Número 03 : ";
    cin >> n3;
    cout << endl;
    if ((n1>n2) && (n1>n3)) {
        p = n1;
        if (n2>n3) {
            s = n2; t = n3;
        } else {
            s = n3; t = n2;
        }
    } else {
        if (n2>n3) {
            p = n2;
            if (n1>n3) {
                s = n1; t = n3;
            } else {
                s = n3; t = n1;
            }
        } else {
            p = n3;
            if (n1>n2) {
                s = n1;   t = n2;
            } else {
                s = n2; t = n1;
            }
        }
    }
    cout << "Descendente : " << p << " - " << s << " - " << t << endl;
    cout << "Ascendente  : " << t << " - " << s << " - " << p << endl;
    return 0;
}

código en C# para ordenar de menor a mayor tres valores ingresados C# :

using System;
using System.Collections.Generic;
using System.Text;
namespace programacion_work
{
    class ordena_numeros
    {
        static void Main(string[] args)
        {
            int n1, n2, n3, p, s, t;
            Console.WriteLine("09. ORDENAMIENTO DE NÚMEROS.\n");
            Console.Write("Ingrese Número 01 : ");
            n1 = int.Parse(Console.ReadLine());
            Console.Write("Ingrese Número 02 : ");
            n2 = int.Parse(Console.ReadLine());
            Console.Write("Ingrese Número 03 : ");
            n3 = int.Parse(Console.ReadLine());
            if ((n1 > n2) && (n1 > n3))
            {
                p = n1;
                if (n2 > n3)
                {
                    s = n2; 
                    t = n3;
                }
                else
                {
                    s = n3; 
                    t = n2;
                }
            }
            else
            {
                if (n2 > n3)
                {
                    p = n2;
                    if (n1 > n3)
                    {
                        s = n1; t = n3;
                    }
                    else
                    {
                        s = n3; t = n1;
                    }
                }
                else
                {
                    p = n3;
                    if (n1 > n2)
                    {
                        s = n1; t = n2;
                    }
                    else
                    {
                        s = n2; t = n1;
                    }
                }
            }
            Console.WriteLine("\nDescendente : " + p + " - " + s + " - " + t);
            Console.WriteLine("Ascendente  : " + t + " - " + s + " - " + p);
            Console.ReadLine();
        }
    }
}

Programar en Java NetBeans que ordene tres números Java NetBeans :

package programacion_work;
import java.util.Scanner;
public class ordena_numeros {
    public static void main(String[] args) {
        Scanner ingreso=new Scanner(System.in);  
        int N1, N2, N3, P, S, T;
        System.out.print("09. ORDENAR NÚMEROS DE FORMA ASCENDENTE Y DESCENDENTE.\n\n");        
        System.out.print("Ingrese Nro 01 : ");
        N1 = Integer.parseInt(ingreso.next()); 
        System.out.print("Ingrese Nro 02 : ");
        N2 = Integer.parseInt(ingreso.next()); 
        System.out.print("Ingrese Nro 03 : ");
        N3 = Integer.parseInt(ingreso.next());     
        if((N1 > N2) && (N1 > N3)){
            P = N1;            
            if(N2 > N3){
                S = N2;
                T = N3;
            }else{
                S = N3;
                T = N2;
            }             
        }else{
            if(N2 > N3){
                P = N2;
                if(N1 > N3){
                    S = N1;
                    T = N3;                
                }else{
                    S = N3;
                    T = N1;
                }                 
            }else{
                P = N3;
                if(N1 > N2){
                    S = N1;
                    T = N2;                
                }else{
                    S = N2;
                    T = N1;
                } 
            } 
        }          
        System.out.println("\nDESCENDENTE : " + P + "," + S + "," + T);
        System.out.println("ASCENDENTE : " + T + "," + S + "," + P); 
    }   
}

mostrar números ordenados en Java NetBeans Java NetBeans - FORMULARIOS [POO]:

private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) {                                              
    int N1, N2, N3, P, S, T;
    N1 = Integer.parseInt(jTxt_Nro1.getText());
    N2 = Integer.parseInt(jTxt_Nro2.getText());
    N3 = Integer.parseInt(jTxt_Nro3.getText());
    if((N1 > N2) && (N1 > N3)){
        P = N1;            
        if(N2 > N3){
            S = N2;
            T = N3;
        }else{
            S = N3;
            T = N2;
        }             
    }else{
        if(N2 > N3){
            P = N2;
            if(N1 > N3){
                S = N1;
                T = N3;                
            }else{
                S = N3;
                T = N1;
            }                 
        }else{
            P = N3;
            if(N1 > N2){
                S = N1;
                T = N2;                
            }else{
                S = N2;
                T = N1;
            } 
        } 
    } 
    JLbl_Desc.setText("DESCENDENTE : " + P + " - " + S + " - " + T);
    JLbl_Asce.setText("ASCENDENTE  : " + T + " - " + S + " - " + P);
} 

Programar en Visual Basic .Net el ordenamiento de 3 valores Visual Basic .NET Console :

Imports System.Console
Module ordenar_numeros
    Dim N1, N2, N3, P, S, T As Integer
    Sub Main()
        WriteLine("09. ORDENAR NÚMEROS DE FORMA ASCENDENTE Y DESCENDENTE.")
        WriteLine("")
        Write("Igrese Número 1 : ")
        N1 = ReadLine()
        Write("Igrese Número 2 : ")
        N2 = ReadLine()
        Write("Igrese Número 3 : ")
        N3 = ReadLine()
        WriteLine("")
        If ((N1 > N2) And (N1 > N3)) Then
            P = N1
            If (N2 > N3) Then
                S = N2
                T = N3
            Else
                S = N3
                T = N2
            End If
        Else
            If (N2 > N3) Then
                P = N2
                If (N1 > N3) Then
                    S = N1
                    T = N3
                Else
                    S = N3
                    T = N1
                End If
            Else
                P = N3
                If (N1 > N2) Then
                    S = N1
                    T = N2
                Else
                    S = N2
                    T = N1
                End If
            End If
        End If
        WriteLine("Descendente : " & P & " - " & S & " - " & T)
        WriteLine("Ascendente  : " & T & " - " & S & " - " & P)
        ReadLine()
    End Sub
End Module

ordenar números en Visual basic Visual Basic .NET Formularios :

Private Sub Btn_Calcular_Click(sender As Object, e As EventArgs) Handles Btn_Calcular.Click
    Dim N1, N2, N3, P, S, T As Integer
    N1 = Txt_Num1.Text
    N2 = Txt_Num2.Text
    N3 = Txt_Num3.Text
    If ((N1 > N2) And (N1 > N3)) Then
        P = N1
        If (N2 > N3) Then
            S = N2
            T = N3
        Else
            S = N3
            T = N2
        End If
    Else
        If (N2 > N3) Then
            P = N2
            If (N1 > N3) Then
                S = N1
                T = N3
            Else
                S = N3
                T = N1
            End If
        Else
            P = N3
            If (N1 > N2) Then
                S = N1
                T = N2
            Else
                S = N2
                T = N1
            End If
        End If
    End If
    Lbl_Msg1.Text = "Descendente : " & P & " - " & S & " - " & T
    Lbl_Msg2.Text = "Ascendente  : " & T & " - " & S & " - " & P
End Sub

Mostrar números ordenados en VBA Excel VBA :

Sub Mayor_Menor()
    Dim N1, N2, N3, S, T, P As Integer
    N1 = CInt(Range("C12").Value)
    N2 = CInt(Range("D12").Value)
    N3 = CInt(Range("E12").Value)
    If (N1 > N2) And (N1 > N3) Then
        P = N1
        If (N2 > N3) Then
            S = N2
            T = N3
        Else
            S = N3
            T = N2
        End If
    Else
        If (N2 > N3) Then
            P = N2
            If (N1 > N3) Then
                S = N1
                T = N3
            Else
                S = N3
                T = N1
            End If
        Else
            P = N3
            If (N1 > N2) Then
                S = N1
                T = N2
            Else
                S = N2
                T = N1
            End If
        End If
    End If
    Range("G12").Value = "Descendente : " & P & " - " & S & " - " & T
    Range("G13").Value = "Ascendente  : " & T & " - " & S & " - " & P
End Sub

Programar el ordenamiento de tres números en excel Excel – InputBox :

Sub Mayor_Menor2()
    Dim N1, N2, N3, S, T, P As Integer
    N1 = CInt(InputBox("INGRESE NÚMERO 1 "))
    N2 = CInt(InputBox("INGRESE NÚMERO 2 "))
    N3 = CInt(InputBox("INGRESE NÚMERO 3 "))
    If (N1 > N2) And (N1 > N3) Then
        P = N1
        If (N2 > N3) Then
            S = N2
            T = N3
        Else
            S = N3
            T = N2
        End If
    Else
        If (N2 > N3) Then
            P = N2
            If (N1 > N3) Then
                S = N1
                T = N3
            Else
                S = N3
                T = N1
            End If
        Else
            P = N3
            If (N1 > N2) Then
                S = N1
                T = N2
            Else
                S = N2
                T = N1
            End If
        End If
    End If
    MsgBox "Descendente : " & P & " - " & S & " - " & T & vbNewLine & "Ascendente  : " & T & " - " & S & " - " & P
End Sub

ordenar números en excel VBA – Formulario [POO] :

Private Sub btn_calcular_Click()
    Dim N1, N2, N3, S, T, P As Integer
    N1 = CDbl(txt_num1.Text)
    N2 = CDbl(txt_num2.Text)
    N3 = CDbl(txt_num3.Text)
    If (N1 > N2) And (N1 > N3) Then
        P = N1
        If (N2 > N3) Then
            S = N2
            T = N3
        Else
            S = N3
            T = N2
        End If
    Else
        If (N2 > N3) Then
            P = N2
            If (N1 > N3) Then
                S = N1
                T = N3
            Else
                S = N3
                T = N1
            End If
        Else
            P = N3
            If (N1 > N2) Then
                S = N1
                T = N2
            Else
                S = N2
                T = N1
            End If
        End If
    End If
    txt_Desc.Text = P & " - " & S & " - " & T
    txt_Asce.Text = T & " - " & S & " - " & P
End Sub



Facebook de www.programacion.work. Canal de Youtube de www.programacion.work. Twitter de www.programacion.work. TikTok de www.programacion.work.


Política de cookies

Política de Privacidad

Aviso Legal y Términos De Uso