Print negative number function

PHOTO EMBED

Sat Jun 08 2024 11:26:05 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>

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

int main (void)
{
    printf("Enter a:\n");
    printf("Enter b:\n");
    printf("Enter c:\n");
    int a,b,c;
    
    scanf("%d%d%d",&a,&b,&c);
    print_quadratic(a,b,c);
    
}

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