quadratic equation

PHOTO EMBED

Thu May 09 2024 10:01:04 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>

void print_quadratic(int a, int b, int c) 
{
    printf("%dx^2 ", a);
    if (b >= 0) {
        printf("+ %dx ", b);
    } else {
        printf("- %dx ", -b);
    }
    if (c >= 0) {
        printf("+ %d", c);
    } else {
        printf("- %d", -c);
    }
    printf("\n");
}


int main() 
{
    int a, b, c;

    printf("Enter a: \n");
    scanf("%d", &a);
    printf("Enter b: \n");
    scanf("%d", &b);
    printf("Enter c: \n");
    scanf("%d", &c);

    print_quadratic(a, b, c);

    return 0;
}
content_copyCOPY

Objective: Create a program that takes three coefficients as inputs and prints a quadratic equation in standard form. Function to Implement: Function name: print_quadratic Parameters: a: Integer. Represents the coefficient of x^2 in the quadratic equation. b: Integer. Represents the coefficient of x in the quadratic equation. c: Integer. Represents the constant term in the quadratic equation. Functionality: The function should print the quadratic equation in standard form, e.g., "5x^2 + 7x - 2". It must handle positive and negative coefficients correctly and display them appropriately. For example: Input Result 3 5 7 Enter a: Enter b: Enter c: 3x^2 + 5x + 7