💻 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 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
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)
#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;
}
#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;
}
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);
}
}
}