~cpp #include <iostream> #include <fstream> using namespace std; int input[11] = {3,3,3,3,3,3,3,3,3,3,3} ; const int INPUT_MAX=11; int x; int number_of_sum=0; int number_of_multiply=0; int Horner(int); void main() { const int SIZE_OF_LINE=5; const int NUMBER_TO_CHAR=48; const int SIZE_OF_BLOCK=4; cout << "x의 값을 입력해주세요.>>"; cin >> x; ofstream outputFile("aswer.txt"); char write_temp[SIZE_OF_LINE][8+INPUT_MAX*SIZE_OF_BLOCK]; for (register int i=0; i<8+INPUT_MAX*4; i++) write_temp[0][i]=write_temp[2][i]=write_temp[4][i]='='; strcpy(write_temp[1]," |index|"); strcpy(write_temp[3]," | data|"); for (register int i=0; i<INPUT_MAX; i++){ write_temp[1][i*SIZE_OF_BLOCK+8]=write_temp[1][i*SIZE_OF_BLOCK+10]=write_temp[3][i*SIZE_OF_BLOCK+8]=write_temp[3][i*4+10]=' '; if (10<=i) write_temp[1][i*SIZE_OF_BLOCK+8]=i/10+NUMBER_TO_CHAR; write_temp[1][i*SIZE_OF_BLOCK+9]=i%10+NUMBER_TO_CHAR; if (10<=input[i]) write_temp[3][i*SIZE_OF_BLOCK+8]=input[i]/10+NUMBER_TO_CHAR; write_temp[3][i*SIZE_OF_BLOCK+9]=input[i]%10+NUMBER_TO_CHAR; write_temp[1][i*SIZE_OF_BLOCK+11]=write_temp[3][i*SIZE_OF_BLOCK+11]='|'; } for (register int i=0; i<SIZE_OF_LINE; ++i){ for (register int j=0; j<8+INPUT_MAX*4; ++j) outputFile << write_temp[i][j]; outputFile << '\n'; } outputFile << "# Horner Function Value ----> "<< Horner(0) << "\n"; outputFile << "# Horner ADD Count ----> "<< number_of_sum << "\n"; outputFile << "# Horner Multiply Count ----> "<< number_of_multiply << "\n"; outputFile.close(); } int Horner(int number) { if (INPUT_MAX-1==number) return input[number]; else{ ++number_of_multiply; ++number_of_sum; return Horner(number+1)*x+input[number]; } }