Есть рабочая программа, считает все правильно. Всего у задачи 2 решения (x=0 и x=1,51). Однако выводится два раза ответ x=0. Как от этого избавиться? Может массив какой вшить, чтобы если ответы равны, то выдавать только один. Помогите, пжл))
Код | #include <stdio.h> #include <math.h> #include <graph.h> #include <conio.h> #define a 0.7 #define b 1.1 #define c 0.2 double ur (double x) {return a*sin(b*sqrt(x))-c*(x*x*x);} main (){ double x, xn,xk,px,py,ymax,ymin,koy,kot,y; char tms[5]; int n=0; puts("Write xn and xk:"); scanf("%lf%lf",&xn,&xk); px = 640/(-xn+xk); _setvideomode(_VRES16COLOR); _clearscreen(_GCLEARSCREEN); ymax= -ur (xn); ymin=ymax; for (x=xn; x<=xk;x+=0.0001) { y=-ur(x);
if((-ur(x-0.0001)*y)<=0.) {printf(" x[%d]=%0.2lf \n",n+1,x); n++} if (ymax<y) ymax=y; if (ymin>y) ymin=y;} if (n==0) puts("net resheniy"); _setwindow (1,xn,-ymin,xk,-ymax); _moveto_w (xn,0.); _lineto_w(xk,0.); _moveto_w (0.,-ymax); _lineto_w(0.,-ymin); py = 480/fabs(-ymax+ymin); koy= (ymax-ymin)/2; _setvieworg(320,240); _setcolor (7); _settextposition (14,76); sprintf(tms,"%2.2f",xk); printf("%s\n",tms); _outtext(tms); _settextposition (14, 1); sprintf(tms,"%2.2f",xn); _outtext(tms); _settextcolor(7); _settextposition(1, 42); sprintf(tms,"%2.2f",-ymin); _outtext(tms); _settextposition(28, 42); sprintf(tms,"%2.2f",-ymax); _outtext(tms); kot = (xk-xn)/2; x = xn; y = -ur(x); _moveto (((x-(xn+kot))*px), ((y-(ymin+koy))*py)); for (x =xn;x <= xk;x+=0.01) { y = -ur(x); _lineto((x-(xn+kot))*px, (y-(ymin+koy))*py);} getch(); return 0;}
|
|