Tuesday, July 28, 2009

Write a program to find the number of even integers and odd integers in a given array in c language?

I won't write it out for you, but I'll tell you how to go about it.





Say you have some array of integers called foo.


Create an int called index.


Create an int called even.





Write a for loop that iterates through each index of foo. If foo[index] mod 2 is 0, that means it's even, therefore increment even. When the loop is finished, even will contain the number of even integers in the array. To find the odds, all you have to do is subtract even from the size of foo.


No comments:

Post a Comment