?
What will be the time complexity of the following code?
What will be the time complexity of the following code?
#include<stdio.h>
int power(int x, int y)
{
int temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
int main()
{
int x = 2;
int y = 3;
printf("%d", power(x, y));
return 0;
}
#include<stdio.h>
int power(int x, int y)
{
int temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
int main()
{
int x = 2;
int y = 3;
printf("%d", power(x, y));
return 0;
}
Join the Discussion
Login to post a comment or share your explanation.
Login