[ create a new paste ] login | about

Link: http://codepad.org/asKH1ifG    [ 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
2
3
4
Line 17: error: conio.h: No such file or directory
In function 'int main()':
Line 38: error: 'getch' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: