4
Vector sum problem, I’m trying to put the sum of the vectors directly into loop, but he is not doing the sum of all but duplicating the last vector, I tested the same code in Portugol and it worked perfectly, what would be the problem in C.
#include <stdio.h>
#include <stdlib.h>
int main() {
int apols[5],i,apolsTotal;
for (i = 1; i <= 5; i++)
{
printf("Digite a sua nota da apol %d\n",i);
scanf("%d",&apols[i]);
apolsTotal = apolsTotal + apols[i];
//aqui esta o problema ele ta somando o ultimo valor com ele mesmo
//no caso apols[5] + apols[5]
}
/*apolsTotal = (apols[1] + apols[2] + apols[3] + apols[4] + apols[5])
formula que funciona mas, não tao pratica*/
printf("Total: %d\n",apolsTotal);
return 0;
}
Failed to initialize total with 0
– Isac