Hello,

i need your help.

I need to make a program which will make sum of digits in number e.g. 123 is 6
BUT, the number could be very big like 1000 digits long or more.(e.g. 1 005 854 684......) - of course without spaces
So, i cannot use datatypes like unsigned long long int, because of it is not enough.
Well, my idea is to store a number into string, then i have to make calculations to make sum of digits.

So, my question is: Is it better to use string (char array) or Int array? Do i need to convert char array to some number only array?

Thanks in advance for any help.

Thank you for answer. It looks good, but prgram wil run on different machines. I cannot install aditional library to every machine.

I don't want to upset you but this library is a C library and compiled into the executable. All skill levels arrive here so take a moment to try the library and see what happens.

I solved it, thank you for help.

Herre is my peace of code:

 // convert (char *)string to numbers and make sum of digits
 int len = strlen(string);
 int count = 0;
 for (int i = 0;i < len ;i++)
    {
        count = count + string[i] - '0';
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.