how to find the sum of first & last digit of a no.
want to do it in python(or any other language) or just logic ?
just logic
i want to know just logic
see if you have a number n 1. n % 10 = last digit e.g n = 1234 a = n % 10 a will be 4 ( % gives the remainder) clear till now ?
yes
now if you do n/10 NOTE : that if you divide int, the decimal gets removed e.g n = n /10 (n = 123 after this step) (because n = 1234 , n/10 = 123.4(in maths) , but int division by int result in int so only 123 gets stored) so if you do it repeatedly you will get at some point n = 1 and this will be first digit clear ?
yes
yes,plz tell me further
finally step 1 : lastdigit = number % 10 step 2 : for first digit use some while loop etc e.g while(n > 0) etc and when loop exits the last digit would be in n actually i don`t want to tell you code directly so you try first , this will help you immensely in improving your logic application and programming if you are struck anywhere post here i am there for help
It's an additional knowledge for me :) Thanks
Join our real-time social learning platform and learn together with your friends!