×
☰ Menu

C Program Area of Traiangle C Program for Prime Number Program 2: Basic salary of an employee Program 3: Write a program to determine the roots of quadratic equation Write a program to find the largest of three numbers using nested if else Receive marks of physics, chemistry, and Math Write a program to find the value of y for a particular value of n Program 7: Write a program to construct a Fibonacci series upto n term. Program-8: Write a program to find whether the number is Armstrong number Program 9: Write a program to generate sum of series 1! +2! +3! +----n! Program 10: Write a program to find the sum of the following series Program 11: Write a program to print the entire prime no between 1 and 300. Program 12: Write a program to print out all the Armstrong number between 100 and 500. Program 13: Write a program to draw the following figure: 3 2 1 21 1 * ** *** Program 14: Write a program to receive a five-digit no and display as like 24689: 2 4 6 8 9 Program 15: Write a function that return sum of all the odd digits of a given positive no entered through keyboard. Program 16: Write a program to print area of rectangle using function & return its value to main function. Program 17: Write a program to calculate the factorial for given number using function. Program 18: Write a program to find sum of Fibonacci series using function Program 19: Write factorial function & use the function to find the sum of series S=1!+2!+-----n!. Program 20: Write a program to find the factorial of given number using recursion. Program 21: Write a program to find the sum of digits of a 5 digit number using recursion. Program 22: Write a program to calculate the GCD of given numbers using recursion. Program 23: Write a program to convert decimal number in to binary number. Program 24: Write a program to convert binary number in to decimal number. Write a program to delete duplicate element in a list of 10 elements & display it on screen. Write a program to merge two sorted array & no element is repeated during merging. Write a program to evaluate the addition of diagonal elements of two square matrixes Write a program to find the transpose of a given matrix & check whether it is symmetric or not

Write a program to determine the roots of the quadratic equation

The standard form of a quadratic equation is: ax2 + bx + c = 0, where a, b and c are real numbers and a! = 0 The term b2- 4ac is known as the discriminant of a quadratic equation.

It tells the nature of the roots. If the discriminant is greater than 0, the roots are real and different. If the discriminant is equal to 0, the roots are real and equal. If the discriminant is less than 0, the roots are complex and different.

 

 

#include <stdio.h>
#include<conio.h>
#include <math.h>
int main() {
    float a, b, c, discriminant, root1, root2, realPart, imagPart;
    printf("Enter coefficients a, b and c: ");
    scanf("%f%f%f", &a, &b, &c);

    discriminant = b*b-4*a*c;

    // condition for real and different roots
    if (discriminant > 0) {
        root1 = (-b + sqrt(discriminant)) / (2 * a);
        root2 = (-b - sqrt(discriminant)) / (2 * a);
        printf("root1 = %.2f and root2 = %.2f", root1, root2);
    }

    // condition for real and equal roots
    else if (discriminant == 0) {
        root1 = root2 = -b / (2 * a);
        printf("root1 = root2 = %.2f;", root1);
    }

    // if roots are not real
    else {
        realPart = -b / (2 * a);
        imagPart = sqrt(-discriminant) / (2 * a);
        printf("root1 = %.2lf+%.2lfi and root2 = %.2lf-%.2lfi", realPart, imagPart, realPart, imagPart);
    }
getch();
    return 0;
}
 

Output of the above Program: 

Enter coefficients a, b and c: 4
3
2
root1 = -0.38+0.60i and root2 = -0.38-0.60i
--------------------------------
Process exited after 15.52 seconds with return value 0
Press any key to continue . . .