Does anyone know what is wrong with this algorithm?
Make a program where the user enters N values and stores the first 10 even numbers in a vector named pair. When you reach the tenth even number, close the program and print the vector ....
#include<stdio.h>
#include<stdlib.h>
#include<locale.h>
int par[10],a,count;
main(){
setlocale(LC_ALL, "Portuguese");
while(count<10){
printf("Digite um número: \n");
scanf("%d",&a);
if(a%2==0){
par[a]=a;
a++;
count++;
}//fim do if
}//fim do while
for(a=1;a<=10;a++){
printf("valores de vetor: %d \n",par[a]);
}//fim do for
system("pause");
}//fim do main
What is happening is the following, when printing the even numbers of the first vector up to the ninth, everything is ok, but the printing of the tenth vector is adding "1" to the number, for example if I type the following sequences,
2 4 6 8 10 2 4 6 8 10
it will print:
2 4 6 8 10 2 4 6 8 "11" ...