array question

  • Thread starter Thread starter t
  • Start date Start date
T

t

I have a 3 digit number that needs to be in an array. I
want to get the last digit. ex. number is 127 and i want
to get the 7.I have a lot of numbers that I will be
working with in a loop. How can I enter this number in an
array and get the last digit only? if that is not possible
can someone give me an alternative? Please give me
examples.
thanks.
 
t said:
I have a 3 digit number that needs to be in an array. I
want to get the last digit. ex. number is 127 and i want
to get the 7.I have a lot of numbers that I will be
working with in a loop. How can I enter this number in an
array and get the last digit only? if that is not possible
can someone give me an alternative? Please give me
examples.
thanks.

You can get the value of the last digit with the "modulus" operator:

int i = 127;
int last = i % 10;

Hans Kesting
 
Back
Top