Hello, I made a function that checks if a number is present in a vector. THE function receives as parameters the vector, the value to be verified and the number of elements in it. E returns 1 (one) if the element exists in the vector or zero if it does not exist. Initialize the vector with the values you want and allow the user to enter, through the keyboard, the constant to be searched for. At the end of the processing the program should tell the user if the constant was found or not.
But after the user enters the number to be searched the compiler hangs. I used the Debug of the Error of Program received signal, Segementation fault. I believe that the error is in the call of the function but I tried in other ways and also it does not give. Help please!
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX 100
int verifica_vetor(int vet[MAX],int n, int tam){//funcao verifica se o vetor contem o numero
int i;
for ( i=0;i<=tam;i++){//laco percorre o vetor
if (n==vet[i]){//verifica se o num digitado esta em alguma das posicoes do vetor
printf("O valor foi encontrado: %d",vet[i]);
return 1;
}else{
printf("\nO valor não foi encontrado.");
return 0;
}
}
}
main() {
int k,i,num, vetor[MAX];
srand(time(NULL));
printf("\n Informe o tamanho do vetor: ");
scanf("%d",&k);
for ( i = 0; i < k; i++) {//preenche o vetor com numero aleatorios de 0 ao numero digitado
vetor[i] = rand() % k + 1;
printf("Vetor[%d] : %d" , i+1, vetor[i]);//vai mostrando o veto
printf("\n");
}
printf("\n Informe o numero que deseja procurar no vetor: ");
scanf("%d",num);
verifica_vetor(vetor,num, k);//chama a funcao de verificar
system("pause");
}