ROOTS OF QUADRATIC EQUATION
Code :
#include<stdio.h>
#include<math.h>
int main()
{
float a, b, c, root1, root2, disc, imag;
printf("==========================================\n");
printf("\tROOTS OF QUADRATIC EQUATION\n");
printf("==========================================\n");
printf("Enter values quadratic equation\n\t ax^2 + bx + c = 0:\n\n");
printf("\ta = ");
scanf("%f", &a);
printf("\tb = ");
scanf("%f", &b);
printf("\tc = ");
scanf("%f", &c);
printf("\n");
disc = ((b * b) - (4 * a * c));
if(disc > 0)
{
root1 = (-b + sqrt(disc)/2 * a);
root2 = (-b - sqrt(disc)/2 * a);
printf("Two distinct and Real roots exists,\n %.2f and %.2f\n", root1, root2);
}
else if(disc == 0)
{
root1 = root2 = -b / (2 * a);
printf("Two Equal and real roots exists,\n %.2f and %.2f\n", root1, root2);
}
else if(disc < 0)
{
root1 = root2 = -b / (2 * a);
imag = sqrt(-disc) / (2 * a);
printf("Two distinct and complex roots exists,\n %.2f + i%.2f and %.2f + i%.2f\n", root1, imag, root2, imag);
}
printf("------------------------------------------\n");
return 0;
}
Come again Learn again !
« iCodeBuzz »
No comments:
Post a Comment