Interview Questions   Tutorials   Discussions   Programs   

C - Write a c program to find the roots of a quadratic equation ax2 + bx + c = 0?




320
views
asked marvit August 24, 2014 09:49 AM  

Write a c program to find the roots of a quadratic equation ax2 + bx + c = 0?


           

1 Answers



 
answered By bhjahnavi   0  
/* program for finding roots of an equation */
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
  float a,b,c,alf,bt,dlt;
  clrscr();

  printf("\n Enter a: ");
  scanf("%f",&a);

  printf("\n Enter b: ");
  scanf("%f",&b);

  printf("\n Enter c: ");
  scanf("%f",&c);

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

  if(dlt==0)
  {
    printf("\n roots are equal ,%f",-b/(2*a));
  }
  elseif(dlt<0)
  {
    printf("\n Imaginary Roots");
  }
  else
  {
    alf=(-b+sqrt(dlt))/(2*a);
    bt=(-b-sqrt(dlt))/(2*a);
    printf("\n\n Alpha = %f\n Beta=%f\n",alf,bt);
  }

  getch();

 }
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert