Write a program to find the solutions of the given quadratic equation.

Source Code

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main (int argc, char *argv[])
{
  clrscr();
  float a,b,c,r1,r2,t;
  printf("\n Enter the co ordinates of the quadratic equation:");
  printf("\n Enter the value preceding x2: ");
  scanf("%f",&a);
  printf("\n Enter the value preceding x: ");
  scanf("%f",&b);
  printf("\n Enter the numeric value: ");
  scanf("%f",&c);
  t=(b*b)-(4*a*c);
  printf("\n The roots of the quadratic equation %fx2+%fx+%f are:",a,b,c);
  if(t==0)
  {
    r1=(b*-1)/(2*a);
    printf("\n only one root : %f",r1);
  }
  else if(t<0)
  {
    printf(" imaginary.");
  }
  else
  {
    r1=((b*-1)+sqrt(t))/(2*a);
    r2=((b*-1)-sqrt(t))/(2*a);
    printf(" %f and %f",r1,r2);
  }
  getch();
}

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code