Загрузка данных


#include <math.h>
#include <stdio.h>

double PI = 3.14159265358;

double Verzera(double x) {
    return 1.0 / (1.0 + x * x);
}

double Bernulli(double x) {
    double value = sqrt(1.0 + 4.0 * x * x) - x * x - 1.0;

    if (value < 0.0) {
        return NAN;
    }

    return sqrt(value);
}

double Hyperbol(double x) {
    if (x == 0.0) {
        return NAN;
    }

    return 1.0 / (x * x);
}

void print_graph(double (*func)(double)) {
    int width = 42;
    int height = 21;

    double x_min = -PI;
    double x_max = PI;

    double y_min = 0.0;
    double y_max = 1.0;

    double x_step = (x_max - x_min) / (width - 1);
    double y_step = (y_max - y_min) / (height - 1);

    for (int row = 0; row < height; row++) {
        double y = y_max - row * y_step;

        for (int col = 0; col < width; col++) {
            double x = x_min + col * x_step;
            double result = func(x);

            if (!isnan(result) && fabs(result - y) <= y_step / 2.0) {
                printf("*");
            } else {
                printf(" ");
            }
        }

        printf("\n");
    }
}

int main() {
    print_graph(Verzera);
    printf("\n");

    print_graph(Bernulli);
    printf("\n");

    print_graph(Hyperbol);

    return 0;
}