Add two big number using string in C / How to add two big numbers using string



 Comment ajouter deux grands nombres en utilisant la chaîne

The most effective way to add two cardinal numbers is using a chord series in C
Adding two numbers in any programming language is simple. For example, in the case that int a = 2; int b = 3, we simply add a + B. At the moment if we try to add two numbers each of 100 numbers like 100000000000000000000000000000000000000 .... , How to advise us to respond
There is no information type with 100 digits in the variable. So what can really be done The cycle is to accept the input as a string. Then, at this point, we can add up these numbers.


For example::



1234...
+
1234...

______

2468...

We simply add from the last series and store the total in a gallery. Then print it from the last component of the gallery.


See :


scorch str1 [ ] = "1234..." ;

scorch str2 [ ] = "1234..." ;

Then, at that point, str1 [3] + str2 [3] = '4' + '4' = 104

Uh-oh, what was the deal It should be 8. Well, not to stress, here the sum is considered an estimate of ASCII. So we must subtract 0 from the series.

Along these lines, (str1 [3] - '0' ) + (str2 [3] - '0') = 4 + 4 = 8;

What happened here?

It is basic , in our series, str1 [3] = 4 and is a person and the ASCII estimate is 52. In the case we subtract the character 0, which contains the ASCII code 48. Then, at this stage, we get 52 - 48 = 4 .

After doing this, we will store all the Assembly in an int-type gallery. Then, at this stage, we simply print them from the last place in the gallery.

At the moment we have another issue. What happens when we add 129 + 124
The last digit is 9 + 4 = 13. In this case, we can use a vector and increase the value of the next expansion. Immediately, the transfer is set to 0 and if the sum is> 9, the transfer becomes 1 in any case it remains 0.


[Note: try to settle on yourself, following the calculation above. If you get bombed, see the code]
Code for adding two main numbers

Delightful programming ...

Comments
1 comment
Post a Comment



Reading Mode :
Font Size
+
16
-
lines height
+
2
-