0

Palindromic number

In order to find out if a number is a palindromic number, the input needs to be spilt up and reversed. How do you split it? Thanks

4th Jun 2021, 7:56 PM
Muhammad Hamza
11 ответов
+ 3
get last digit (using %) and divide by 10 until number reach 0 ^^
4th Jun 2021, 8:26 PM
visph
visph - avatar
+ 5
You can also try this as well... 1.Convert `n` in to string using to_string(int) function... 2.scan the string from beginning and end, up to middle..and check that if corresponding elements are equal or not.. If yes , return true Otherwise false
5th Jun 2021, 5:15 AM
saurabh
saurabh - avatar
+ 1
by converse operation (assuming you want to join them in reverse order): initialize a variable to zero (or use the previous one) for each digits, multiply the variable by 10 and add digit to it...
4th Jun 2021, 10:36 PM
visph
visph - avatar
+ 1
you doesn't need an array if you use another variable (initialized to zero) to store the resulting reverse number: then you do both operation in once loop ;P
4th Jun 2021, 11:14 PM
visph
visph - avatar
+ 1
Yep, thanks again!
4th Jun 2021, 11:56 PM
Muhammad Hamza
+ 1
Muhammad Hamza use strings It might cause a bug in your program if you use division or other ways
6th Jun 2021, 6:51 PM
Mani_K_A
0
And how do you join them back?
4th Jun 2021, 10:33 PM
Muhammad Hamza
0
That’s smart Thanks!
4th Jun 2021, 10:53 PM
Muhammad Hamza
0
Oh and what about storing the individual digits? I understand that an array should be used, but how do you create an array that’s just as big as the number of digits?
4th Jun 2021, 11:11 PM
Muhammad Hamza
0
I see, thanks!
7th Jun 2021, 6:53 PM
Muhammad Hamza