![Algoritmo que busca número al azar](https://programacion.work/vectores/img/busca-numero-al-azar-en-pseint.png)
Vector - Array - Vector Unidimensional [1 Columna, n Filas].
💻 Cargar un vector con 10 números, luego ingresar por teclado un valor y si lo encuentra mostrar su posición de ese o varios números que sean iguales al ingresado.
Algoritmo programacion_work
Definir f, arreglo, num, int como Entero;
Dimension arreglo[10];
int <- 0;
Escribir "11. BUSCA UN VALOR AL AZAR.";
Para f <- 0 Hasta 9 Con Paso 1 Hacer
arreglo[f] <- azar(30);
FinPara
Escribir Sin Saltar "VALOR A BUSCAR DE (0 - 29): ";
Leer num;
Escribir "";
Escribir "VALORES DEL ARREGLO ";
Para f <- 0 Hasta 9 Con Paso 1 Hacer
Escribir Sin Saltar arreglo[f], " ";
FinPara
Escribir "";
Escribir "";
Para f <- 0 Hasta 9 Con Paso 1 Hacer
Si (num == arreglo[f]) Entonces
Escribir "EL VALOR ESTÁ EN LA POSCICIÓN : ", f+1;
int <- 1;
FinSi
FinPara
Si (int == 0) Entonces
Escribir "VALOR NO ENCONTRADA";
FinSi
FinAlgoritmo
import random
sw = 0
arreglo = [int() for ind0 in range(10)]
# 11. BUSCA UN VALOR AL AZAR.
for f in range(9):
arreglo[f] = random.randint(0,29)
num = int(input("VALOR A BUSCAR [0 - 29] : "))
print("\nVALORES DEL ARREGLO")
for f in range(9):
print(arreglo[f], end=" ")
print("\n")
for f in range(9):
if(num == arreglo[f]):
print("EL VALOR ESTÁ EM ÑA POSICIÓN : ", f+1)
sw = 1
if(sw == 0):
print("VALOR NO ENCONTRADO")
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
srand(time(NULL));
int num, sw=0, arreglo[10];
printf("11. BUSCA UN VALOR AL AZAR.\n");
for(int f=0; f<=9; f++){
arreglo[f] = 0+rand()%(30-0);
}
printf("VALOR A BUSCAR DE (0 - 29): ");
scanf("%d",&num);
printf("\nVALORES DEL ARREGLO\n");
for(int f=0; f<=9; f++){
printf("%d ", arreglo[f]);
}
for(int f=0; f<=9; f++){
if(num == arreglo[f]){
printf("\nEL VALOR ESTA EN LA POSCICION : %d ",(f+1) );
sw = 1;
}
}
if(sw == 0){
printf("\nVALOR NO ENCONTRADO");
}
return 0;
}
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main() {
int num, sw=0, arreglo[10];
cout << "11. BUSCA UN VALOR AL AZAR." << endl;
for(int f=0; f<=9; f++){
arreglo[f] = 0+rand()%(30-0);
}
cout << "VALOR A BUSCAR DE (0 - 29): ";
cin >> num;
cout << "\nVALORES DEL ARREGLO" << endl;
for(int f=0; f<=9; f++){
cout << arreglo[f] << " ";
}
cout << endl;
for(int f=0; f<=9; f++){
if(num == arreglo[f]){
cout << "\nEL VALOR ESTA EN LA POSCICION : " << (f+1) << endl;
sw = 1;
}
}
if(sw == 0){
cout << "\nVALOR NO ENCONTRADO" << endl;
}
return 0;
}