Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get an integer -unit digit in a simple way

Tags:

objective-c

i am not sure about my english, but i need to get the unit digit of an integer. WITHOUT complex algorithm but with some API or another trick.

for example :

int a= 53;
int b=76;

this i add because i almost always dont "meet the quality standards" to post! its drive me crazy! please , fix it ! it took me 10 shoots to post this,and other issue also.

i need to get a=3 and b=6 in a simple smart way.

same about the other digit.

thanks a lot .

like image 408
Curnelious Avatar asked Dec 12 '22 06:12

Curnelious


2 Answers

here is how to split the number into parts

int unitDigit = a % 10; //is 3
int tens= (a - unitDigit)/10; //is 53-3=50 /10 =5
like image 101
Michał Zygar Avatar answered Jan 03 '23 18:01

Michał Zygar


You're looking for % operator.

a=a%10;//divides 'a' by 10, assigns remainder to 'a'
like image 42
MadhavanRP Avatar answered Jan 03 '23 19:01

MadhavanRP