I am trying to count the number of odd values in the elements of the array. Is there a way to perform the below operation without declaring a variable inside the for loop? I am aware that the variable declared inside the loop cannot be accessed outside the loop and I want to know if there is a way that the following loop is performed and the value of oddValueCountKS could be accessed outside of the loop.
int arr[3] = {1004, -237890, 30022};
for (int i = 0; i < 3; i++) {
int oddValueCountKS = 0;
while (arr[i] != 0) {
if (arr[i] % 2) {
oddValueCountKS++;
}
arr[i] /= 10;
}
}