# Thread: Does anyone know how to do exponent with just addition?

1. ## Does anyone know how to do exponent with just addition?

I am working on a program to create a calculator with only addition. I still need subtraction, division, and exponent. I am having trouble with this if anyone could help it would be greatly appreciated. 2. Multipication with addition is easy enough (which you seem to have gotten already).

Exponent is simply repeated multiplication.

a^2 = a * a
a^3 = a * a * a

Why not simply have a loop to call your multiplication code, while holding the current product?

Fractional exponents and negative exponents may be a little more difficult. 3. do I need a nested loop or just do my multiplication then get that sum and multiply it again 4. Code:
```while the iterator is less than the exponent
total = base * total
iterator++
end loop```
except obviously replace the multiply with whatever you are using to multiply (hopefully a function, as that would make sense). 5. Originally Posted by cowboyz209 do I need a nested loop or just do my multiplication then get that sum and multiply it again
Don't nest them... use one loop to get your first product then a second loop to do exponentiation on the product.
There should be no reason to repeatedly calculate the same number... 6. i am trying to do this with using only addition so far i have

insert
Code:
```for (i = 0; i < num2; i++){
sum = sum + num1;
sum++;``` 7. That's not much. Why is that all you have? You were presented with perfectly useful ideas for implementing such a routine.

Why use cryptic names like num1 and num2 - call one exponent and the other base.

Anyway, what is it supposed to do? Does it work? 8. alright so i have
insert
Code:
```     for(i = 0; i < num1; i++){
sum = sum + num2;
for(i = 0 ; i < num1 ; i++){
sum = sum + num1;
}
}``` 9. That's a joke, isn't it?

Did you compile it? Do you not see what happens to i if you reuse it like that?

Where's your respectful use of my suggestion to use descriptive variable names? 10. its not a joke...just change the names to exponent and base same thing.

insert
Code:
```  for (i = 0; i < exponent ; i++){
sum = sum + exponent; }
for(i = 0; i < exponent; i++){
sum = sum + base;
)``` 11. How about posting your entire code rather than a snippet that doesn't do anything. The question is does this compile? The answer is clearly a big fat NO. 12. okay well i was just needing help with the for loop for the exponential function everything else complies right Popular pages Recent additions c programming 