1
A program that asks to find the largest number of an array, typing the amount of elements and until which element it will verify. However, in this program that I did it is not considering the first element typed. If I type 5, 4, 3, 2, 1 it says the biggest is 4. I have no ideas how to solve
int i, qntd, n;
printf ("Digite a quantidade de elementos: ");
scanf ("%d", &qntd);
printf ("Ate onde considerar: ");
scanf ("%d", &n);
float vet[qntd], maior = 0;
for (i = 0; i < qntd; i++) { //Preencher o vetor
printf ("Digite um numero: ");
scanf ("%f", &vet[i]);
}
for (i = 0; i < n; i++) {
if (i == 0) {
vet[i] = maior;
}
if (vet[i] > maior) {
maior = vet[i];
}
}
printf ("Maior = %.2f \n", maior);
system ("PAUSE");
Sure you need to read a number for quantity and another for the
n
? Taking advantage, your entry is incomplete: you did not say whichqntd
and whichn
you typed. And if said your input is with 2 numbers less than it should– Jefferson Quesado