[ASSIGNMENT] Long calculation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 24

[ASSIGNMENT] Long calculation

Your 5-year old relative wants to learn how to do long addition/subtraction/multiplication/division but keeps on forgetting what to do. Thus you decided to help him out by making a simple code for him. Your code should take a one-liner input, the calculation done e.g. 67+92 These are the inputs and their outputs calculate('47+89') 1 4 7 + 8 9 --------- 1 3 6 --------- calculate('86-48') (7) 1 8 6 - 4 8 --------- 3 8 --------- So you get the essence? Start coding now!

20th Sep 2017, 11:32 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
36 Answers
+ 21
I enjoyed this so much! 👍👍! My try (Addition & Subtraction & Multiplication & Division): https://code.sololearn.com/W6w3bIRGpEU6/?ref=app
25th Sep 2017, 10:17 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 14
$Vengat : I am sure that this is the hardest among all the 68 code challenges I played.
26th Sep 2017, 11:26 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 11
$Vengat : Did the changes you asked! Check the code now.
26th Sep 2017, 11:38 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 11
I gave up on this challenge. Too hard especially if you use java.
17th Dec 2017, 4:48 AM
qwerty
qwerty - avatar
+ 10
And, do you think I should change something in my code? If so, mention it and I will try to do it.
26th Sep 2017, 11:29 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 9
Can the input be more than one line? Im having a hard time doing it
21st Sep 2017, 12:29 AM
qwerty
qwerty - avatar
17th Nov 2017, 1:41 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 7
@Krishna sir great code😊😊
26th Sep 2017, 11:40 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
Is there some range limit for C++ users? You see, we can't store numbers > 2^32 -1 in long long, but since this is a code for a 5 year old, I assume this limit is enough...
26th Sep 2017, 3:00 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 7
My division algorithm works for 9279/59 and 92793/69, but gives a wrong answer in 999/3. I am not able to understand why. Help! https://www.sololearn.com/Discuss/744571/long-calculation-help-in-division-needed All I need is something that works for all cases, and the Rem function is all that needs to be rewritten...
27th Sep 2017, 11:30 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 7
I tried ....but got little success... working only for (+) update 1: Another try....come up with solution for both (+ and -) operations. Also with some more development in the older logic... update 2: One more try....and got the solution for multiplication (*) also....now my code is working for (+, -, *)..... https://code.sololearn.com/cioKl107L2B4/?ref=app https://code.sololearn.com/cji8u1rlrCI6/?ref=app https://code.sololearn.com/c7T4tvd6AH2n/?ref=app
1st Oct 2017, 8:23 PM
Sanjeev Kumar
Sanjeev Kumar - avatar
+ 6
Sir Krishna is a genius! Happy I helped in his joy! Not quite what I wanted but oh well,it is really good
25th Sep 2017, 1:03 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
@ReimarPB Who, Me? No I didn't. I make my codes myself... This is a continuation of Yash Thatte's Code... And the mult and divt functions are as original as they can be...
28th Sep 2017, 2:42 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
Now my code is updated for addition(+), substraction(-) and multiplication (*).... Request to all ..... kindly chcek my code and give your views plz... https://code.sololearn.com/cioKl107L2B4/?ref=app
22nd Oct 2017, 11:56 AM
Sanjeev Kumar
Sanjeev Kumar - avatar
+ 5
Your stuff looks different from what ive learned in school
21st Sep 2017, 5:55 AM
Supersebi3
Supersebi3 - avatar
+ 5
Very Long Challenge... ¿¿¿-_-???
24th Sep 2017, 2:21 AM
Ekansh
+ 5
Good job for the addition part
24th Sep 2017, 10:36 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Nope. I am gonna make an awesome login-logout system with python using file writing
26th Sep 2017, 11:35 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
No, you must be able to remove the operator yourself
21st Sep 2017, 4:13 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
Personally I prefer Ben Lobb's it has no additional 0s
25th Sep 2017, 5:37 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar