Quote:
Originally Posted by sahana
how can we compute the pow of real huge numbers like pow(1000,1000) or even more in c?
i guess even long double can't be used in this case as it results in overflow.
i guess the bit representations is a way but still pretty clueless.
It must be implemented in C and not any other language.
Please share your ideas for this problem.
|
This is simple using math functions. even pow function may be implemented this way..
#include <stdio.h>
#include <math.h>
double pow(double a, double b)
{
return(exp(b*log(a)));
}
int main()
{
double a, b;
printf("Enter a, b: ");
scanf("%lf%lf", &a, &b);
printf("%lf ^ %lf = %lf\n", a, b, pow(a, b));
}
you need to device a funcion which calls pow in breakups for example
1000^200
pow(1000,100) + pow(1000,100)
and sub results should be added and stored in string format
add using formulas for addition of such numbers.
i.e., 1e+300 + 1e+300
which will be equal to 2e+300 where e is 10
Regards
Sriram