Archived
Работы по программированию
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#include <graphics.h>
|
||||
#include <math.h>
|
||||
|
||||
void drawGraph() {
|
||||
int gd = DETECT, gm;
|
||||
initgraph(&gd, &gm, "");
|
||||
|
||||
int x, y;
|
||||
int max_x = getmaxx();
|
||||
int max_y = getmaxy();
|
||||
int origin_x = max_x / 2;
|
||||
int origin_y = max_y / 2;
|
||||
|
||||
// Draw axes
|
||||
line(0, origin_y, max_x, origin_y); // X-axis
|
||||
line(origin_x, 0, origin_x, max_y); // Y-axis
|
||||
|
||||
// Plot the function
|
||||
for (x = -origin_x; x <= origin_x; x++) {
|
||||
float fx = (float)x / 10; // Scale x for better visibility
|
||||
float fy = ((fx + 4) * (fx * fx + 3 * fx + 2)) / (fx + 1);
|
||||
y = origin_y - (int)(fy * 10); // Scale y for better visibility
|
||||
|
||||
putpixel(origin_x + x, y, GREEN);
|
||||
}
|
||||
|
||||
getch();
|
||||
closegraph();
|
||||
}
|
||||
|
||||
int main() {
|
||||
drawGraph();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user