C++ PROGRAMS 04 FOR MECHANICAL

4. Find the solution of given quadratic equation. ( IF-ELSE Statement)
#include <stdio.h>
#include <math.h>
main()
{
  float a, b, c, dis, root1, root2;
  printf(" Input the values of a, b and c\n");
  scanf("%f%f%f", &a, &b, &c);
  dis = b*b - 4*a*c;
  if(dis < 0)
    printf(" *******The roots are imaginary*******\n\n");
  else
   {
    root1 = (-b+sqrt(dis))/(2*a);
    root2 = (-b-sqrt(dis))/(2*a);
    printf(" The roots are %5.4f and %5.4f", root1, root2);
   }
  return 0;
}

Comments

Popular posts from this blog

Industrial Attachment

লেনজ এর সুত্র