Presentation is loading. Please wait.

Presentation is loading. Please wait.

Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 0 S1 = S2 = S3 =

Similar presentations


Presentation on theme: "Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 0 S1 = S2 = S3 ="— Presentation transcript:

1 Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 0 S1 = S2 = S3 =

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

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

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

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

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

7 Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 1 S1 = S2 = S3 = First iteration ( i=1 ): S3 = [tmp S3]; 1 4 4

8 Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): 4

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

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

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

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

13 Add two strings representing numbers + 8 8 7 42 9 1 63 5 Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): Carry = floor(n/10); 4 1 0

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

15 Add two strings representing numbers + 8 8 7 42 9 1 63 5 Carry = 1 S1 = S2 = S3 = Second iteration ( i=2 ): S3 = [tmp S3]; 4 1 0 0

16 Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 1 S1 = S2 = S3 = Third iteration ( i=3 ): 40


Download ppt "Add two strings representing numbers + 8 87 42 9 1 63 5 Carry = 0 S1 = S2 = S3 ="

Similar presentations


Ads by Google