ALGORITMO MUESTRA LA POSICIÓN DEL NÚMERO EN EL VECTOR

Vector - Array - Vector Unidimensional [1 Columna, n Filas].


Algoritmo que busca número al azar

Buscar un numero en un vector en PSeInt

💻 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 en pseint que búsca si un número estan en un vector PSeInt Estricto :

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

código en python que muestra si un valor se encuentra guardado en el vector Python :

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")

código en Dev C++ que muestre si un valor ingresado está en el vector LENGUAJE C:

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

código en Dev C++ que muestra si un valor está dentro del vector Dev C++ :

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



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