linesguy

Any length number adder

Mar 28th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. 10 text : pr#0
  2.  
  3. 0 rem Numbers to add:
  4. 20 n1$ = "1946284628648198247651913"
  5. 30 n2$ = "8175832638363856421903252"
  6.  
  7. 0 rem Make numbers same length by adding 0's at the start
  8. 40 if len(n2$) < len(n1$) then n2$ = "0" + n2$ : goto 40
  9. 50 if len(n1$) < len(n2$) then n1$ = "0" + n1$ : goto 50
  10.  
  11. 0 rem Add numbers:
  12. 100 for x = len(n1$) to 1 step -1
  13. 110 n = val(mid$(n1$,x,1)) + val(mid$(n2$,x,1)) + c
  14. 115 c = 0 : rem
  15. 120 if n > 9 then c = 1 : n = n - 10 : rem (c)arry
  16. 130 f$ = str$(n) + f$
  17. 140 next
  18.  
  19. 0 rem Add the final "1" if needed:
  20. 145 if c = 1 then f$ = "1" + f$
  21.  
  22. 0 rem Print:
  23. 150 ? n1$:?"+":?n2$:?"=":?f$
Add Comment
Please, Sign In to add comment