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

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

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

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';

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';

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

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

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

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

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

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

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

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

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

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

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

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

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