Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.

Solution For C Program - 

Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.

#include <stdio.h>

int trova_elemento(int a){

int vettore[]={7,17,436,1,436,246,753,32,446,375486,52,1,45,7};

int i;
int trovato;
trovato=0;

for(i=0; i<14 && trovato==0; i++){
if(a==vettore[i]){
trovato=1;
printf("L'elemento %d è stato trovato ed è in posizione %d\n", a, i+1);
}
}

if(trovato==0)
printf("L'elemento %d non esiste nel vettore\n", a);

return 0;
}


int main(void){
int elemento;

printf("Inserisci il numero da cercare nel vettore: \n");
scanf("%d", &elemento);

trova_elemento(elemento);
return 0;
}


Learn More :