Go Down

Topic: Get digits of integer (Read 636 times) previous topic - next topic


If I have an integer, how to I see how many digits it is, and how to I grab single numbers from certain places? Like the number 45, how do I get that it is 2 digits, and how do I ask for the first digit to get 4 and the second digit to get 5?



The integer 45 is not the same as the number 45.
The first is used for calculation, the second is only used for display and are 2 characters: '4' and '5'.

int a= 45 / 10 // a = 4
int b = 45 % 10 // b = 5

Use the same construction if you want 100, 1000, etc.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131