Im trying to write a program that takes array inputs from the user and assigns the the odd elements to the first index until there are no more odd elements and the even elements are assigned to the end of the array until they're done so for example
Assuming this a size 10 array,The user enteres 1 for the first element and 2 for the second element and 3 for the third element ,so the final array would have indices 0 and 1 to have the values of 1 and 3 and indice 10 to have the value of 2 and so on and so forth,and here's my code
int main() {
int array1[31];
int array2[31];
for(int i=0;i<31;i++) {
if(scanf("%d",&array1[i])%2==0) {
array2[31-i]=array1[i];
}
else {
array2[i]=array1[i]
}
}
for (int i=0;i<31;i++) {
printf ("%d\t",array2[i]);
}
return 0;
}
But this code is only printing exactly what the user has entered in the exact same order,it's like my if condition doesn't execute and im not sure why,I'm still a beginner in C so I apologize if this problem is too trivial,but yeah any help is appreciated
Aucun commentaire:
Enregistrer un commentaire