Wednesday, January 5, 2011

Program to find out roots of a quadratic equation

/*  Name: Program to find out roots of a quadratic equation

Author: Parveen Malik

Date: 05/01/11 21:00*/


#include<stdio.h>

#include<conio.h>

#include<math.h>
void main()

{

int a,b,c;

float disc; // Discriminant

float root1,root2;

printf("Enter the value of a,b and c respectively\n");

printf("a = ");

scanf("%d",&a);

printf("b = ");

scanf("%d",&b);

printf("c = ");

scanf("%d",&c);

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

root1=-b+sqrt(disc)/2*a;

root2=-b-sqrt(disc)/2*a;

if(disc==0)

{

printf("Roots are real and equal\n");

printf("First Root :%.2f = Second Root: %.2f\n",root1,root2);

}

else if(disc<0)

{

printf("Roots are imaginary");

printf("First root = %.2f\n",root1);

printf("Second root = %.2f\n",root2);

}

else

{

printf("Roots are real and distinct\n");

printf("First root = %.2f\n",root1);

printf("Second root = %.2f\n",root2);

}

getch();

}

[caption id="attachment_82" align="aligncenter" width="655" caption="OUTPUT"]Program to find out roots of a quadratic equation[/caption]

0 comments:

Post a Comment