-2
I’m putting together a little program that aims to count how many prime numbers are present in a vector and tell the user the amount. In this case, if the vector has 5 primes, the program must print the number 5.
int primos(int n, int* vet)
{
int i, prim;
for(i = 0; i < n; i++){
for(i = 2; i <= vet[i]/2; i++){
if(vet[i]%i==0){
prim++;
}
}
}
return(prim);
}
int main()
{
int i, n, prim;
printf("Digite o Tamanho do vetor: ");
scanf("%d", &n);
int* vet = (int*) malloc(n*sizeof(int));
if(vet == NULL){
printf("Erro de alocação!");
exit(1);
}
printf("Digite os elementos do vetor: ");
for(i = 0; i < n; i++){
scanf("%d", &vet[i]);
}
prim = primos(n, vet);
printf("O vetor tem %d Numero(s) primo(s).", prim);
free(vet); return 0;
}
I’m having a hard time with this program, you’d be able to help me complete it?
What is your difficulty, implementing some logic, or fixing a problem? Is it a build error? Runtime error? Different result than expected? Describe what you need.
– Andre
I wanted tips on how to make it.
– Sydius