Hey guys, I'm building a program in C that can get powers of 2. The user inputs the value of n, and the program calculates 2^n.
Here's the code
#include <stdio.h>
double power(int n)
{
int q;
double c=2;
for (q=n; q>1; q--) {c=2*c;}
return c;
}
int main()
{
int n;
double output;
scanf("%i",&n);
output=power(n);
printf("%.0lf",output);
return 0;
}
The problem comes when I input 100
What I am getting 1,267,650,600,228,229,400,000,000,000,000
What I should get 1,267,650,600,228,229,401,496,703,205,376
I've tried to modify the program, but so far, no luck...
It has to be coded entirely in ANSI C. Any ideas on how to increase the precision?