C program to find roots of a quadratic equation

Roots of a quadratic equation

In this C program, we will learn how to find the roots of a quadratic equation[ax2 + bx + c]. When we try to solve the quadratic equation we find the root of the equation. Mainly roots of the quadratic equation are represented by parabola in 3 different patterns like

  • No Real Roots
  • One Real Root
  • Two Real Roots

When we solve the equation we get 3 conditions mentioned above using this formula:-
X = [-b (+or-)[Squareroot(pow(b,2)-4ac)]]/2a


Python program to find roots of quadratic equation


  • Step 1:- Start.
  • Step 2:- Take user inputs for a,b and c.
  • Step 3:- Check if the value of a is not zero.
  • Step 4:- Calculate Functions value ie, b*b – a*a*c.
  • Step 5:- Find the square root of the function.
  • Step 6:-if the value is greater than zero print Two real roots and value of roots.
  • Step 7:- If the value is equal to zero Print one real root and print the value.
  • Step 8:- If both the condition are false print no real roots and print values.

C program to find the square root of a quadratic equation

#include <stdio.h>
#include <math.h>
int main()
    int a, b, c;
    int val, root;
    printf("enter value of a : ");
    printf("enter value of b : ");
    printf("enter value of c : ");
        printf("a cannot be zero");
        val = (b*b) - (4*a*c);
        root = sqrt(val);
            printf("two real roots\n");
        else if(val==0)
            printf("One real root\n");
            printf("No real root\n");
            printf("%d + i %d\n",-b/(2*a),root);
            printf("%d - i %d\n",-b/(2*a),root);
    return 0;
Enter value of a :1
Enter value of b :-7
Enter value of c :12
Two Real Roots