//二分查找函数 void FindAnswer(double x1, double y1, double x2, double y2) { if (y1==0) { printf("Answer is %lf\n",x1 ); } else { if (y2==0) { printf("Answer is %lf\n", x2); } else { double x0, y0; x0=(x1+x2)/2; y0=NumOfFuntion(x0); if (y0==0) { printf("Answer is %lf\n",x0 ); } else { if (fabs(x1-x2)<=pow(10,-5)) { printf("Answer is %lf\n",x0 ); } else { if (y1*y0<0) { printf("Answer is in (%lf,%lf)\n", x1,x0); FindAnswer(x1,y1,x0,y0); } else { if (y0*y2<0) { printf("Answer is in (%lf,%lf)\n", x0,x2); FindAnswer(x0,y0,x2,y2); } else { printf("No Answer\n"); } } } } } } }
static void ProcessCourse(courseDB course) { questionT q; int qnum; string ans; int index; printf("%s\n", course->title); qnum = 1; while (qnum != 0) { q = course->questions[qnum]; AskQuestion(q); ans = ConvertToUpperCase(GetLine()); index = FindAnswer(ans, q); if (index == -1) { printf("I don't understand that.\n"); } else { qnum = q->answers[index].nextq; } } }
int main () { FindAnswer(2,NumOfFuntion(2),4,NumOfFuntion(4)); return 0; }