• 04-30-2011
cowboyz209
I am trying to make a calculator program using addition only...I have made the code for multiplication, but am having trouble with - and division.
I created division with just subtraction but can't figure it out with addition.

heres my one example:
insert
Code:

```int divide, divis, quotient; printf("Enter Number 1:"); scanf("%d", &divide); printf("Enter Number 2:"); scanf("%d", &divis); quotient=0; while(divide > 0){ divide = divide - divis; quotient++; } printf("%d\n, quotient);```
• 04-30-2011
winterhawk787
Use the Euclidean Division algorithm with your algorithm for multiplication if you're using integers. Here's a link to read up on it. The translation to code is pretty easy. If you're messing with decimal values, you're going to need something else, but this will solve your issue with integer division.

Euclidean algorithm - Wikipedia, the free encyclopedia

Specific info:
Division and Euclidean algorithms

More specific info:
http://www.cargalmathbooks.com/10%20...gorithm%20.pdf
• 04-30-2011
cowboyz209
yes i am using integers, so can I use that for both division and subtraction?
• 04-30-2011
winterhawk787
Not exactly. It's not a solve-all algorithm, unfortunately, but you can use some operations on sets (in C, arrays) to do subtraction by addition. Read up a little on it, because it's set theory mathematics, but I imagine someone on this forum could come up with a better way of doing it than I.