Please Visit: http://ift.tt/1ajReyV
from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1l3777w
via LifeLong Community
Write a C program to calculate pow(x,n) | GeeksforGeeks
Time Complexity of optimized solution: O(logn)
Let us extend the pow function to work for negative y and float x.
/* Extended version of power function that can work for float x and negative y*/#include<stdio.h> float power(float x, int y){ float temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else { if(y > 0) return x*temp*temp; else return (temp*temp)/x; }}
http://ift.tt/1l3777t
http://ift.tt/1l3777u
Time Complexity of optimized solution: O(logn)
Let us extend the pow function to work for negative y and float x.
/* Extended version of power function that can work for float x and negative y*/#include<stdio.h> float power(float x, int y){ float temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else { if(y > 0) return x*temp*temp; else return (temp*temp)/x; }}
http://ift.tt/1l3777t
http://ift.tt/1l3777u
from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1l3777w
via LifeLong Community
No comments:
Post a Comment