Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. void main()
  5. {
  6. int a,b,c;
  7. float fa,fb,fc,total[2],sqrcheck;
  8.  
  9. printf("Enter the Coefficients: ");
  10. scanf("%d %d %d",&a,&b,&c);
  11.  
  12. switch(a){
  13. case 0: break;
  14. case 1: printf("x^2"); break;
  15. case -1: printf("-x^2"); break;
  16. default: printf("%dx^2",a);
  17. }
  18.  
  19. switch(b){
  20. case 0: break;
  21. case 1: printf("x"); break;
  22. case -1: printf("-x"); break;
  23. default: if(a==0 || b<0){printf("%dx",b);}else if(b>0){printf("+%dx",b);}
  24. }
  25.  
  26. switch(c){
  27. case 0: break;
  28. case 1: if(a==0&&b==0){printf("1");}else {printf("+1");}; break;
  29. case -1: printf("-1"); break;
  30. default: if(a==0 && b==0 || c<0){printf("%d",c);}else if(c>0){printf("+%d",c);};
  31. }
  32.  
  33. fa = a;
  34. fb = b;
  35. fc = c;
  36.  
  37. sqrcheck = pow(fb,2) - (4.0*fa*fc);
  38. total[0] = (- fb + sqrt(sqrcheck)) / (2.0*fa);
  39. total[1] = (- fb - sqrt(sqrcheck)) / (2.0*fa);
  40.  
  41. if(sqrcheck>=0 && fa != 0){
  42.  
  43. printf("\nx = %.5g and %.5g",total[0],total[1]);
  44. }
  45. else if(sqrcheck < 0){
  46. printf("\nROOT DOES NOT EXIST...\nTHE VALUE UNDER ROOT IS (%g)",sqrcheck);
  47. }
  48. else if(a == 0){
  49. printf("\nINFINITY or It is not a QUADRATIC EQUATION.\nBUT CURRENT VALUE UNDER ROOT IS (%g)",sqrcheck);
  50. }
  51. else{
  52. printf("\nThere is no Answer");
  53. exit(0);
  54. }
  55. getchar();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement