fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4.  
  5. #define PI 3.14
  6.  
  7. int main(void)
  8. {
  9.  
  10. puts("---- ROOTS ----");
  11.  
  12. char equ[20]; //Quadratic Expression in an Array
  13. float a,b,c,ope;
  14. float root1,root2;
  15.  
  16. printf("please provide the expression :");
  17. scanf("%s",equ);//Example : 5x^2+3x+1 as input NOT
  18.  
  19. a = equ[0]-'0';//since ax^2+bx+c in the above expression a==5
  20. b = equ[5]-'0';//b==3
  21. c = equ[8]-'0';//c==1
  22. //printf("\n%f %f %f",a,b,c);
  23.  
  24. ope = sqrt(b*b -4*a*c);
  25. printf("\n%f",ope);
  26. root1 = (-b + ope)/(2*a);
  27. root2 = (-b - ope)/(2*a);
  28.  
  29. printf("\nThe root 1 of the expression is : %f", root1);
  30. printf("\nThe root 2 of the expression is : %f", root2);
  31.  
  32. return EXIT_SUCCESS;
  33. }
Success #stdin #stdout 0s 9424KB
stdin
2x^2+3x+1
stdout
---- ROOTS ----
please provide the expression :
1.000000
The root 1 of the expression is : -0.500000
The root 2 of the expression is : -1.000000