How to find odd and even numbers in string array using func

How to find odd and even numbers in string array and put the odd number in array and even numbers in another array using func
This is the array
string n[5][5] = { { "1", "2", "3", "4","5" }
,{ "6", "7", "8", "9","10" }
,{ "11", "12", "13", "14","15" }
,{ "16", "17", "18", "19","20" }
,{ "21", "22", "23", "24","25" } };
Last edited on
2 ways... you can convert the strings to integers and use %2 or you can look at the last character in the string and check it against a lookup table. The lookup table is faster.

char lut[256] = {0};
lut['0'] = 1;
lut['2'] = 1;
lut['4'] = 1;
lut['6'] = 1;
lut['8'] = 1;

if( lut[n[x][y].back()])
// even
else
//odd


Topic archived. No new replies allowed.