개 ¶
구 거, 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];
}










