You are missing break
statements, so you code falls-through (ie: cascades) for each statement. Also, you are missing a default
case, which is poor form, and should be corrected. Make the switch this:
switch(X[i]) {
case 2:count++;
break;
case 3:count++;
break;
case 5:count++;
break;
case 7:count++;
break;
default:
break;
}
Finally, you can make your code a bit safer by replacing:
int size = 23;
With:
int size = sizeof(X) / sizeof(int);
A word of caution when using the sizeof
function: if you are using it on a function parameter, it will fail due to "pointer decay", a topic worth reading up on.