U E D R , A S I H C RSS

호너의법칙/박영창

, 히 100 파;;

code

~cpp
/**
Chapter 1.2 (2)Problem Solving
programmed by eternalbleu (youngchang park, 2001 1612)

Date: 2005 09 10
**/
#include <iostream>
//  
#define EXIT_SUCCESS    0
#define EXIT_FAILURE    1

#define PARAM_X		2.0
#define COEFFICIENTS	{1, 2, 3, 4, 5, 6, 7}

double horner_func(double, double*, int);

int max_exponentials = 0;

int main ()
{
	double x_param = PARAM_X;

	// index    .
	double coefficient [] = COEFFICIENTS;

	max_exponentials = sizeof(coefficient) / sizeof(double);

	std::cout<<horner_func(x_param, coefficient, 0)<<std::endl;
	
	return EXIT_SUCCESS;
}

/**
horner_func 호   .
@param x_param    .
@param coefficient    .
@param exponential  .

@return 호   + 호  
**/
double horner_func(double x_param, double* coefficient, int exponential)
{
	// Recursion Termination Condition
	if (exponential == max_exponentials-1) return coefficient[exponential];
	// General Recursion Call
	return horner_func(x_param, coefficient, exponential+1)*x_param + coefficient[exponential];
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:33
Processing time 0.0088 sec