HACER UN ALGORITMO QUE GENERE UN NÚMERO ALEATORIO

Categoría de Estructura Repetitiva Para


Genere un número aleatorio en PSeInt

💻 Encontrar un número aleatorio de 1 a 20, se tiene 3 intentos, sino lo encuentra en cada búsqueda le dará una pista ya sea si es mayor o menor al número a encontrar.


Algoritmo en pseint para encontrar un número aleatorio PSeInt Estricto : DESCARGA EL CÓDIGO

Algoritmo en pseint de youtube short VER EL CÓDIGO
Algoritmo programacion_work
    Definir i, numA, num, sw como Entero;	
    sw <- 0;
    numA <- aleatorio(1,20);	
    Para i <- 1 Hasta 3 Con Paso 1 Hacer
        Escribir Sin Saltar "ENCUENTRE EL NÚMERO DE [1 - 20] : ";
        Leer num;
        Si (num == numA) Entonces
            Escribir "NÚMERO ENCONTRADO";
            sw <- 1;
            i <- 3;
        SiNo
            Si (num > numA) Entonces
                Escribir "INGRESE UN NÚMERO MENOR";
            SiNo
                Escribir "INGRESE UN NÚMERO MAYOR";
            FinSi
        FinSi	
        Escribir "";
    FinPara	
    SI (sw == 0) Entonces
        Escribir "EL NÚMERO A ENCONTRAR ERA : ", numA;
    FinSi
FinAlgoritmo
Algoritmo en pseint para encontrar un número aleatorio

código en python que encuentre un número al azar con 3 intentos Python :

print("BÚSCAR UN NÚMERO ENTRE [1 a 20]")
import random
sw = 0
numA = random.randint(1,20)
for i in range(3):
    num = int(input("ENCUENTRE EL NÚMERO DE [1 - 20] : "))
    if (num == numA):
        print("NÚMERO ENCONTRADO")
        sw = 1
        break
    else:
        if (num > numA):
            print("INGRESE UN NÚMERO MENOR")
        else:
            print("INGRESE UN NÚMERO MAYOR")
    print()
if (sw == 0):
    print("EL NÚMERO A ENCONTRAR ERA : ",numA)

código en Lenguaje C para encontrar un número aleatorio LENGUAJE C :

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
    int num=0, numA, sw=0;	
    srand(time(NULL));
    numA = 1+rand()%(21-1);
    for (int i=1; i<=3; i++){
        printf("ENCUENTRE EL NUMERO DE [1 - 20] :");   
        scanf("%i",&num);
        if(num == numA){
            printf("\nNUMERO ENCONTRADO\n");
            sw = 1;
            break;
        }else{
            if(num > numA){
                printf("\nINGRESE UN NUMERO MENOR\n");
            }else{
                printf("\nINGRESE UN NUMERO MAYOR\n");
            }
        }        
    }	
    if(sw == 0){
        printf("\nEL NUMERO A ENCONTRAR ERA : %d",numA);
    }	
    return 0;
}

código en Dev C++ dónde se tiene tres intentos para encontrar un número Dev C++ :

#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main() {
    int num=0, numA, sw=0;	
    srand(time(NULL));
    numA = 1+rand()%(21-1);
    for (int i=1; i<=3; i++){
        cout << "ENCUENTRE EL NUMERO DE [1 - 20] : ";
        cin >> num;
        if(num == numA){
            cout << "NUMERO ENCONTRADO" << endl;
            sw = 1;
            break;
        }else{
            if(num > numA){
                cout << "INGRESE UN NUMERO MENOR" << endl;
            }else{
                cout << "INGRESE UN NUMERO MAYOR" << endl;
            }
        }
        cout << endl;    
    }	
    if(sw == 0){
        cout << "EL NUMERO A ENCONTRAR ERA : " << numA << endl;
    }
    return 0;
}


Algoritmo que muestre un número random generado en Java NetBeans Java NetBeans :

package programacion_work;
import java.util.Scanner;
public class busca_numero_aleatorio {
    public static void main(String[] args) {   
        Scanner ingreso=new Scanner(System.in);
        int num=0, numA, sw=0;
        numA = (int)(Math.random()*(20-10+1)+10);
        System.out.println(numA);
        for (int i=1; i<=3; i++){
            System.out.print("ENCUENTRE EL NUMERO DE [1 - 20] : ");
            num = Integer.parseInt(ingreso.next());    
            if(num == numA){
                System.out.println("NUMERO ENCONTRADO");
                sw = 1;
                break;
            }else{
                if(num > numA){
                    System.out.println("INGRESE UN NUMERO MENOR");
                }else{
                    System.out.println("INGRESE UN NUMERO MAYOR");
                }
            }
            System.out.println("");            
        }          
        if(sw == 0){
            System.out.println("EL NUMERO A ENCONTRAR ERA : " + numA); 
        }        
    }     
}



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