i made a postfix calculator using stacks in c.
i want to know how to right stack code for calculating exponentiation?
i want to know this part only
example
this is the stack commands for adding numbers
case '+':
push(pop() + pop());
break;
i made a postfix calculator using stacks in c.
i want to know how to right stack code for calculating exponentiation?
i want to know this part only
example
this is the stack commands for adding numbers
case '+':
push(pop() + pop());
break;
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
yep what he said , except I am not sure if you can do 2 pops on 1 line like that... something about multiple side-effects or something or the other..
Using a for loop would be good. Using a stack??
I suppose it could be done - as could a sled dog race with dachshunds. Once you have the number, and you have the exponent in your variables, what do you want the stack for?