개 ¶
료구 로 나라, 랑 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];
}










