Take a no, eg 9. Square it.
9^{2}=81
Now add the digits
8+1= 9 (Which is the original number)
How do I do this using Functions?
It should work for any number. 9, 55, 395 Any.
Printable View
Take a no, eg 9. Square it.
9^{2}=81
Now add the digits
8+1= 9 (Which is the original number)
How do I do this using Functions?
It should work for any number. 9, 55, 395 Any.
Hello siddharthbandhu!
What have you done so far? Do you have the logic for what you are trying to do?
To get the digits of a number look at using the % and / operators
you can use .length() to determine how many digits and .charAt() to isolate the numbers and add them using a for loop.