0

# Sum of char arrays.

I have two char arrays str1 and str2. They are defined like this: char *str1 = "9998"; char *str2 = "3"; I want to sum them and return it in an array. How could you do that? An example code would be nice. The output of said function must be "10001".

21 odpowiedzi

+ 2

http://www.sololearn.com/app/cplusplus/playground/cfuJgxA2eXf6/
without using any library functions and dynamic memory

0

I don t know why you use type int like char ?!

0

I want to sum big numbers. And by big i mean really big. 10000 digits numbers or more. So a built-in data type does NOT apply here.

0

do you know how to write in file?
you write all characters on seperate file(str1 in file1 and str2 in file2) and then pick the two numbers by using 2 long double variables......
there is another method but that is more complicated....you will use for loops and the function expr ()
add numbers by multiplying with 10^i to a single double variable.
I never tried it but I am pretty sure it'll work
I am sorry I read your post after I wrote this answer

0

Mukul: Long double variables cant store a 1000 digit number. the maximum is 1.79769e+308, hence, 308 digits.

0

I already edited my answer .......

0

atoi coverts the string to integers. with 1000+ digit numbers that doesnt work.

0

how it will store upto 1000+ digits?

0

there is a possible data loss....@ramesh

0

try dynamic allocated memory.....if you only wanna add then creat some dynamic int pointers

0

With respect to ur question, how many digits needed or largest number?

0

Converting to built in datatype doesnt apply here. It is possible to do operations with 10000+ digits. I've just done it. This is like an exercise. I will upload the code in a little bit.

0

@ramesh: lets put 10000 digits max.

0

example give one number

0

@ramesh: actually, i have a real max value. the maximum number of digits is the maximum posible value of unsigned int data-type.

0

@ramesh: i dont understand your question.

0

unsigned int can hold max 10 digit number : 4294967295. Is it my understanding correct?

0

thats right. So the numbers must have less than 2^32 digits. Actually you wrote 2^32 as the max value of unsigned int. that is not correct. unsigned int can store 2^32 values, but one of them is 0, so the max value is 2^32 - 1.