Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
#include <stdio.h>
#include <math.h>

#define HEIGHT 20
#define WIDTH 50

// Function to evaluate the quadratic equation for a given x
double quadraticEquation(double a, double b, double c, double x) {
    return a * x * x + b * x + c;
}

int main() {
    double a, b, c;
    printf("Enter the coefficients of the quadratic equation (y = ax^2 + bx + c):\n");
    printf("a: ");
    scanf("%lf", &a);
    printf("b: ");
    scanf("%lf", &b);
    printf("c: ");
    scanf("%lf", &c);

    printf("\nGraph of y = %.2lfx^2 + %.2lfx + %.2lf\n", a, b, c);

    // Draw the graph
    for (int y = HEIGHT; y >= -HEIGHT; y--) {
        for (int x = -WIDTH; x <= WIDTH; x++) {
            double x_real = x / 10.0;
            double y_real = quadraticEquation(a, b, c, x_real);

            if (fabs(y_real - y) <= 0.5) {
                printf("*");
            } else if (y == 0 && x != 0) {
                printf("-");
            } else if (x == 0 && y != 0) {
                printf("|");
            } else if (x == 0 && y == 0) {
                printf("+");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}