0
In the vector below 300 elements, I need to store the distinct elements that occur in another vector called values. Then I have to record how many times the i-th value of the vector values occurs in the first vector. I started to make the vector code of 300 values but then do not know from there, I thank for the attention
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
void lernumeros(int A[]){
for(int i = 0; i <= 300; i++) {
printf("\nDigiite um valor qualquer positivo:\n");
scanf("%d", &A[i]);
if(i < 0){
printf("Numeros Negativos não são permitidos!");
break;
}
}
}
return 0;
}
It is not every C compiler that correctly interprets functions declared within functions. I can also observe that you are taking the closed interval of
[0,300]
, which gives a total of 301 elements; leave the end of the range open:[0,300)
– Jefferson Quesado
Also, to check the number typed, do not check by
i
, but forA[i]
– Jefferson Quesado
Related: https://answall.com/q/217720/64969
– Jefferson Quesado
Do the elements need to be in the single vector in the same order as in the original vector? Because my first reflex is to sort the vector using
qsort()
and then copy each new value as soon as it changes in the ordered vector, copying the same beforehand to a array draft, if necessary.– Wtrmute