Что-то вот такого типа:
1) файл ITERATE.H:
#ifndef __ITERATE_H__
#define __ITERATE_H__
void init_graph();
float iterative(float);
double recursive(double, double, double);
void gra();
extern int x0, y0, m, w, x1, y1, x2, y2, x3, y3;
#endif
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
#include "ITERATE.H"
/*
Var a,i,b,k,Err,x0,y0,x1,y1,m,w,x3,y3,x2,y2:integer;
x,y,s:extended;
*/
int x0, y0, x1, y1, x2, y2, x3, y3, m, w;
void init_graph() {
int error_code, graph_mode, graph_driver = DETECT;
initgraph(&graph_driver, &graph_mode, "");
if((error_code = graphresult()) != grOk) {
printf("Error Graphic Initialize: %s\n", grapherrormsg(error_code));
getch();
exit(1);
}
}
float iterative(float x) {
// var a,b:real;
float a = x, s = 0;
float b = 1;
while(fabs(a / b) > 0.001) {
s += a / b;
a *= (-x*x);
b += 2;
}
return s;
}
double recursive(double a, double x, double b) {
if(fabs(a / b) > 0.01)
return recursive(a*(-x*x), x, b+2) + (a / b);
else return 0;
}
void gra() {
x0=200; y0=250;
m =150; w =150;
setcolor(GREEN);
// coord.line.x
line(0,450,639,450);
// arrows x
line(639,450,629,445);
line(639,450,629,455);
// coord.line.y
line(200,0,200,479);
// arrows y
line(200,0,205,10);
line(200,0,195,10);
// text.x; text.y
outtextxy(210, 5, "Y");
outtextxy(630,435, "X");
outtextxy(205,455, "0");
outtextxy( 50,455,"-1");
outtextxy(350,455, "1");
setlinestyle(DASHED_LINE, 0, 1);
line(350,450,350,50);
line(50,455,50,50);
setcolor(GREEN);
setlinestyle(SOLID_LINE, 0, 0);
rectangle(380,120,385,125);
outtextxy(390,120,"Function y=arctan(x)");
setcolor(RED);
rectangle(380,140,385,145);
outtextxy(390,140,"Iterative");
setcolor(MAGENTA);
rectangle(380,160,385,165);
outtextxy(390,160,"Recursive");
setcolor(GREEN);
outtextxy(390,180,"for next - press ENTER");
getch();
double x = -1, y;
while(x <= 1) {
y = atan(x);
x1 = (int)(x0 + x*w);
y1 = (int)(y0 - y*m);
putpixel(x1, y1, GREEN);
x += 0.001;
}
getch();
x = -1;
while(x <= 1) {
x2 = (int)(x0+x*w);
y2 = (int)(y0-iterative(x)*m);
putpixel(x2, y2, RED);
x += 0.001;
}
getch();
x = -1;
while(x <= 1) {
x3 = (int)(x0+x*w);
y3 = (int)(y0-recursive(x,x,1)*m);
putpixel(x3, y3, MAGENTA);
x += 0.001;
}
getch();
// end.else.point.
}
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include "ITERATE.H"
// Uses Crt,Graph,Iterate;
// Var a,b,i,k,Err,x0,y0,x1,y1,m,w,x2,y2,x3,y3:integer;
// x,y,s:extended;
int main() {
clrscr();
double x = -1;
textcolor(WHITE);
cprintf("|| X || Iterative || Recursive || Arctg ||\n\r\n\r");
while(x <= 1.05) {
if(x > 0) textcolor(LIGHTRED);
else textcolor(LIGHTGREEN);
cprintf("|| %+3.2f || %+3.2f || %+3.2f || %+3.2f ||\n\r",
x, iterative(x), recursive(x, x, 1), atan(x)
);
x += 0.1;
}
textcolor(LIGHTGREEN);
cprintf("\n\rpress any key for graphics drawing...");
getch();
init_graph();
gra();
getch();
closegraph();
return 0;
}
Огромное спасибо. Да, конечно, разберусь)