# simple math/c question

This is a discussion on simple math/c question within the C Programming forums, part of the General Programming Boards category; Hello everyone! I need to write a program in C, but i'm stuck. This is what I have to do: ...

1. ## simple math/c question

Hello everyone!

I need to write a program in C, but i'm stuck.
This is what I have to do:
A program, that will add two base-5 numbers and display the result on the screen afterwards.

The problem is, that when you add two numbers in C, they will always be added like they're base-10 numbers of course. How to avoid that?

Thank you very much,
unimatrix

2. How do you add numbers that are bigger than a single digit on paper? You carry anything over 10. Certainly you can figure out how to change a 10 into a 5.

Quzah.

3. Thanks for the reply quzah. You've made quite a good point. I certainly can add any based numbers on paper. But the problem is I don't know how to do that in C. Well, to be honest, I'm not quite an experienced programmer yet.
I'm not asking you to write me a program or anything, but any clue would be welcome.

Thanks,
unimatrix

4. Computers calculate in base 2 - base 5 would just be a visual representation of the result.

Like with this non-portable function
http://www.mkssoftware.com/docs/man3/itoa.3.asp

5. There are a few ways you could approach this. One way would be to take the input, which will be in base 5, convert it to base 10, use C's inbuilt arithmetic operators to do your calculation, convert back to base 5, then output the number. Another way would be to store each base 5 digit (pendit? quingit? I don't know...) in an array, and add them like you would do on paper. To do it this way, you'd work out the steps you take when adding by hand, then convert them into C code. The trickiest thing in this method would probably be working out how much to carry and how much to keep in each column. The modulus operator (%) would likely be quite useful at this point.

I'm sure there are other ways, those are just the first two that sprang to mind. Which way you choose to do it depends on what the requirements of your task are.

6. ## Success!

Hey, I just wanted to tell you that after almost one week of trying i've finaly succeeded

Thanks,
unimatrix