Hey there.

I'm trying to figure out how to subtract one array of integers from another. I have figured out how to add 2 together going digit by digit and carrying over. I have no idea how to go about subtracting one from another. Basically i want to do simple calculations on numbers that long long wouldn't hold. I also want to do it using the standard library.

Does anyone have any hints on how to start or a link to a tutorial?

Any help is most appreciated.

Recommended Answers

All 2 Replies

There might be a better way to do this, but this is just my idea:

1. determine sign of the result
2. make all cstring'd numbers positive
3. big number always goes on top
4. smaller number always goes on bottom
5. perform right-to-left subtraction just like you learned in 2nd grade.
6. apply proper sign to result

If anyone knows a better way to do this, let me know.

thanks got it now:)

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.