#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
/* Program calculate root of Quadrtatic Equation */
/*General form of quadratic equation ax^2+bx+c =0 */
int a,b,c,d; /* d is a discriminent */
float x1,x2,x,y; /* here x1 is root1 and x2 is root2 */
printf("\nEnter the value of a:");
scanf("%d",&a);
printf("\nEnter the value of b:");
scanf("%d",&b);
printf("\nEnter the value of c:");
scanf("%d",&c);
d=b*b-4*a*c;
x1=-b/(2*a);
x2=x1;
printf("\nRoot of x1= %f\n",x1);
printf("\nRoot of x2= %f\n",x2);
x=(-b+sqrt(d))/(2*a);
y=(-b-sqrt(d))/(2*a);
printf("\nFirst Root x1= %f\n",x);
printf("\nSecond Root x2= %f\n",y);
getch();
return 0;
}
No comments:
Post a Comment