Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/Objective-C read and get last digit of integer?

How can i get the last digit of an integer (or NSInteger) outputted to integer?

example:

int time = CFAbsoluteGetCurrent();
int lastDigit;
like image 339
Daniel says Reinstate Monica Avatar asked Dec 30 '10 02:12

Daniel says Reinstate Monica


People also ask

How do you get the last digit of a number C?

To find the last digit of a number, we use modulo operator %. When modulo divided by 10 returns last digit of the input number.

How do I find the first digit of an integer?

To find first digit of a number we divide the given number by 10 until number is greater than 10. At the end we are left with the first digit.


1 Answers

Use modulo:

int lastDigit = time % 10;
like image 79
Georg Fritzsche Avatar answered Sep 30 '22 08:09

Georg Fritzsche