[ create a new paste ] login | about

Link: http://codepad.org/GNrRBRP3    [ raw code | output | fork ]

C, pasted on Oct 10:
#include<stdio.h>
#include<conio.h>


double Power_n(double x, long n)
{
	// n >= 0
	double result = 1;
	while(n--)
	{
		result = result * x;
	}
	return result;
}
double qPower_n(double x, long n)
{
	// n >= 0
	double result = 1;
	while(n)
	{
		if(n % 2 == 1)
		{
			result = result * x;
		}
		x = x * x;
		n = n / 2;
	}
	return result;
}
int main()
{
	double x = 3;
	long n = 2;
	double z;
	z = qPower_n(x, n);
	printf("z = %f", z);

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments: