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


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

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

double lemniscate(double x) {
    double y;
    double value;

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

    if (value < 0.0) {
        y = -1.0;
    } else {
        y = sqrt(value);
    }

    return y;
}

double hyperbola(double x) {
    double y;

    if (x == 0.0) {
        y = -1.0;
    } else {
        y = 1.0 / (x * x);
    }

    return y;
}

void print_graph(int type) {
    const double pi = 3.14159265358979323846;
    double x;
    double y;
    double max_y;
    int row;
    int col;
    int point;

    if (type == 1) {
        max_y = 1.0;
    } else if (type == 2) {
        max_y = 0.5;
    } else {
        max_y = 170.4;
    }

    row = 0;
    while (row < 21) {
        col = 0;

        while (col < 42) {
            x = -pi + 2.0 * pi * col / 41.0;

            if (type == 1) {
                y = versiera(x);
            } else if (type == 2) {
                y = lemniscate(x);
            } else {
                y = hyperbola(x);
            }

            if (y < 0.0) {
                printf(" ");
            } else {
                point = 20 - (int)(y * 20.0 / max_y + 0.5);

                if (point == row) {
                    printf("*");
                } else {
                    printf(" ");
                }
            }

            col++;
        }

        printf("\n");
        row++;
    }
}

int main(void) {
    print_graph(1);
    printf("\n");
    print_graph(2);
    printf("\n");
    print_graph(3);

    return 0;
}