Download presentation

Presentation is loading. Please wait.

Published byJustine Dugdale Modified about 1 year ago

1
Add two strings representing numbers Carry = 0 S1 = S2 = S3 =

2
Add two strings representing numbers Carry = 0 S1 = S2 = S3 = First iteration ( i=1 ): n1 = S1(length(S1)+i-1)-'0';

3
Add two strings representing numbers Carry = 0 S1 = S2 = S3 = First iteration ( i=1 ): n2 = S2(length(S2)+i-1)-'0';

4
Add two strings representing numbers Carry = 0 S1 = S2 = S3 = First iteration ( i=1 ): n = n1 + n2 + Carry; 1 4

5
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = First iteration ( i=1 ): Carry = floor(n/10); 1 4

6
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = First iteration ( i=1 ): tmp = char(mod(n,10)+'0'); 1 4 tmp

7
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = First iteration ( i=1 ): S3 = [tmp S3]; 1 4 4

8
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): 4

9
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): n1 = S1(length(S1)+i-1)-'0'; 4

10
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): n2 = S2(length(S2)+i-1)-'0'; 4

11
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): n = n1 + n2 + Carry; 4 1 0

12
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): n = n1 + n2 + Carry; 4 1 0

13
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): Carry = floor(n/10); 4 1 0

14
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): tmp = char(mod(n,10)+'0'); tmp

15
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): S3 = [tmp S3];

16
Add two strings representing numbers Carry = 1 S1 = S2 = S3 = Third iteration ( i=3 ): 40

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google