+ 2

Algorithm

How to create an algorithm that will exclude the first and last digit and add the middle digits For example: 1234 So in this it should exclude 1 and 4 but add 2 and 3 without using String

19th Dec 2017, 2:50 PM
Satvik Singh Rathore
Satvik Singh Rathore - avatar
3 odpowiedzi
+ 6
Input: 1234 * Divide the number by 10 So, we now have 123. That removed the last digit for us. We now need to make sure our number is greater than or equal to 10, and keep on adding together the next digits. Get the next digit with: myNum % 10 Steps: 1234 / 10 = 123. 123 > 10, so we keep going. 123 % 10 = 3. 123 / 10 = 12. 12 > 10, so we keep going. 12 % 10 = 2. 12 / 10 = 2. 2 < 10, therefore we are finished. 3 + 2 was 5.
19th Dec 2017, 5:02 PM
Rrestoring faith
Rrestoring faith - avatar
+ 4
Here's the code that does the work :-) https://code.sololearn.com/cvU0CY2v5HFm/?ref=app
20th Dec 2017, 4:56 PM
Riyad Arshad
Riyad Arshad - avatar
+ 3
take input in form of string. Ignore the first and last characters and then run a loop parse characters and add them.
19th Dec 2017, 4:01 PM
shobhit
shobhit - avatar