0
The error is that the printing of the numbers is appearing duplicated.
The code:
#include <stdio.h>
#include <stdlib.h>
int maiorValor(int *array[], int *q);
int main()
{
int N, k;
int vetor[] = {0};
printf("Qual o tamanho do array: ");
scanf("%d", &N);
printf("Quantos valores por linha: ");
scanf("%d", &k);
fflush(stdin);
for(int r = 0; r < N; r++)
{
vetor[r] = rand()%99;
}
int res = maiorValor(vetor, N);
for(int r = 0; r < N; r++)
{
for(int l = 0; l < k; l++)
{
printf("%d ", vetor[r]);
}
printf("\n");
}
printf("\nO maior valor foi: %d", res);
return 0;
}
int maiorValor(int *array[], int *q)
{
int maior = array[0];
for(int r = 0; r < q; r++)
{
if(array[r] > maior)
{
maior = array[r];
}
}
return (maior);
}
Do you have to use pointers in this code? Did I test you have a problem with the pointers? In the code
rand()%99
generates values up to 98, but the image gives to see much higher values– Bernardo Lopes
Dude, it’s not very clear to me what’s duplicated... Is it what’s being printed inside the for? If that’s it, just remove the for... Have you tried debugging, seeing step by step what is occurring...
– Leonardo Alves Machado
Also, you are allocating a vector of a single space instead of allocating a vector with the desired element size
– Leonardo Alves Machado
I didn’t understand what you meant by "vector of a single space".
– Rafael S.
Your pointer is only enough to store a single integer value, not a vector
– Bernardo Lopes