/* This is HW3 check for roots
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 2nd, 2024.
*/

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

int main() {
    float a_EU, b_EU, c_EU;

    printf("Enter the value of a: \n");
    scanf("%f", &a_EU);

    printf("Enter the value of b: \n");
    scanf("%f", &b_EU);

    printf("Enter the value of c: \n");
    scanf("%f", &c_EU);

    if (a_EU == 0) {
        printf("Not a quadratic equation\n");
    } else {
        float discriminant_EU = b_EU * b_EU - 4 * a_EU * c_EU;

        if (discriminant_EU == 0) {
            // Two equal real roots
            float root_EU = -b_EU / (2 * a_EU);
            printf("Two equal real roots: %.2f\n", root_EU);
        } else if (discriminant_EU > 0) {
            // Two unequal real roots
            float root1_EU = (-b_EU + sqrt(discriminant_EU)) / (2 * a_EU);
            float root2_EU = (-b_EU - sqrt(discriminant_EU)) / (2 * a_EU);
            printf("Two unequal real roots: %.2f and %.2f\n", root1_EU, root2_EU);
        } else {
            // Two conjugate complex roots
            float realPart_EU = -b_EU / (2 * a_EU);
            float imaginaryPart_EU = sqrt(-discriminant_EU) / (2 * a_EU);
            printf("Two conjugate complex roots: %.2f + %.2fi and %.2f - %.2fi\n", realPart_EU, imaginaryPart_EU, realPart_EU, imaginaryPart_EU);
        }
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: