[ create a new paste ] login | about

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

Ruby, 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
2
3
Line 5: syntax error, unexpected tIDENTIFIER, expecting kDO or '{' or '('
double Power_n(double x, long n)
                               ^


Create a new paste based on this one


Comments: