Saturday, 15 March 2014

C++ Which Number Doesn't Belong? -



C++ Which Number Doesn't Belong? -

i'm kind of beginner programming, while writing programme of own, ran roadblock can't seem around.

anyway, given set of numbers these in array:

4 14 24 27 34

you can see how of numbers except 1 have 4 in ones place. how write function can homecoming number different in ones place, 27 in case? numbers different every time programme run, due scenario, 4 of them have same digit in ones place. wouldn't in numerical order.

i couldn't seem find way mathematically, nor able find through search. ideas?

write programme using % operator take unit place value

void check () { int i, changeindex =0; ( = 0; < 5; i++) { (int k = 0; k < 5; k++) { if (a[i]%10 == a[k]%10) { changeindex++; } } if (changeindex != 4) { break; } changeindex = 0; } cout<<a[i]; }

this work count of 5 , if 1 of numbers have different unit place value

c++

No comments:

Post a Comment