Hey guys, sorry if this has been asked before, but I couldn't find an answer anywhere.
How would one write 3^i without using .math? (i being numbers 0-9)
More specifically, this is what I have:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x, n, answer1, first;
x = 3;
n = 10;
first = 1;
float answer2;
int i;
answer2 = 1.0;
answer1 = 1;
answer1 = x;
for (i = 0; i < n; i++) {
printf("%5d %d %1.9f\n", answer1, i, answer2);
answer1 = x << i;
answer2 = 1.00/answer1;
}
return EXIT_SUCCESS;
}
And this is what I want it to produce:
1 0 1.0
3 1 0.333333343
9 2 0.111111112
27 3 0.037037037
81 4 0.012345679
243 5 0.004115226
729 6 0.001371742
2187 7 0.000457247
6561 8 0.000152416
19683 9 0.000050805
I believe I am only having troubles with the first column, any help would be appreciated