0
Well I’m doing a program that needs to know the indexes of the highest values in the vector, but I’m not getting the code I tried.
#include <stdio.h>
int main(int argc, char** argv)
{
double vetor[10];
int indice[10], c = 0;
for(int i = 0; i < 10; i++)
{
scanf("%lf", &vetor[i]);
}
double maior = vetor[0];
for(int i = 0; i < 10; i++)
{
if(vetor[i] > maior)
{
maior = vetor[i];
indice[c] = i + 1;
c++;
}
}
for(int i = 0; i < c; i++)
{
printf("%d ", indice[i]);
}
return 0;
}
Your goal is to find the index only of the highest number ? If yes why
indice
is a vector with 10 positions ?– Isac
It is not only of the largest number, but of the largest numbers of the vector
– rafael marques
Of the greatest ? But how many ? By their example seem to be all
10
, which wouldn’t make much sense. Better try to clarify and give an example of input numbers and output result.– Isac
numbers 1 2 3 4 5 6 7 8 9 10 indices of the highest values 0 1 2 3 4 5 6 7 8 9
– rafael marques
Then the
0
is the first word to appear, but in the position0
is the lowest value. There is no confusion ?– Isac