0
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int X[10], cont;
cont=0;
while(cont<10){
printf("Digite um numero inteiro: ");
scanf("%d",&X[cont]);
if(X[cont] %2 == 0){
X[cont]=0;
}else{
X[cont]=1;
}
cont++;
}
while(cont<10){
printf(" %d ", X[cont]);
cont++;
}
}
This code is not working, but when I do for
works:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int X[10], cont;
for(cont=0;cont<10;cont++){
printf("Digite um numero inteiro: ");
scanf("%d",&X[cont]);
if(X[cont] %2 == 0){
X[cont]=0;
}else{
X[cont]=1;
}
}
for(cont=0;cont<10;cont++){
printf(" %d ", X[cont]);
}
}
Note that at the end of the first while the variable
cont
will be set to 10 and therefore will not enter the second loop. Restart the variable before entering the second loop.– anonimo
Okay, thanks. It worked!
– Barbara Coltro
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero