All pastes #196899 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-10-10 23:22 UTC
rendered paste body
Write the definition of a function  powerTo , which receives two parameters. The first is a  double and the second is an  int . The function returns a  double . 

 If the second parameter is negative, the function returns 0. Otherwise, it returns the value of the first parameter raised to the power of the second. 



------------


double powerTo(double num, int pwr)
{
	if (pwr > 0)
	{
		for (int i=1; i < pwr; i++)
		{      
			num = (num*num);      
		}    
		return num;
	}
	else {
		return 0;
	}
}