~cpp #include <iostream.h> #include <fstream.h> int X; int a[11]={3,3,3,3,3,3,3,3,3,3,3}; int i; int function_value=0; int num_add=0,num_multiply=0; int j=a[0];//j는 an의 역할을 한다. void main() { cout <<"X에 들어갈 수를 입력해주세요:"; cin >>X; ofstream outputFILE; outputFILE.open("C:\honer.txt"); for(i=0;i<10;i++){ int t=a[i+1];//t는 an-1의 역할을 한다. function_value=j*X+t; j=function_value;//j는 같은 식을 반복하기 위한 변수.처음에 j는 an, 그다음에는 an*X+an-1이 된다. num_add++; num_multiply++; } cout<<"=====================================================\n"; outputFILE<<"=====================================================\n"; cout<<"|index| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | \n"; outputFILE<<"|index| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | \n"; cout<<"=====================================================\n"; outputFILE<<"=====================================================\n"; cout<<"| data| 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | \n"; outputFILE<<"| data| 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | \n"; cout<<"=====================================================\n"; outputFILE<<"=====================================================\n"; cout<<"# Horner Function Value ---->"<<function_value<<endl; outputFILE << "# Horner Function Value ---->"<<function_value<<endl; cout<<"# Horner ADD Count ---->"<<num_add<<endl; outputFILE << "# Horner ADD Count ---->"<<num_add<<endl; cout<<"# Horner Multiply Count ---->"<<num_multiply<<endl; outputFILE << "# Horner Multiply Count ---->"<<num_multiply<<endl; outputFILE.close(); }