Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define FIO "written by\nManakina Alyona"
  4. #define gr "student group 833"
  5. #define lr7 "Laboratory work 7"
  6. #define stars printf("\n****************")
  7. void representation() // Student presentation function
  8. {
  9. stars;
  10. printf("\n%s\n%s\n%s", lr7, gr, FIO);
  11. stars;
  12.  
  13. }
  14.  
  15.  
  16. void get_roots( double a, double b, double c, double x1, double x2, double d) // The function to calculate the roots of the equation,
  17. {
  18. if (a == 0) // where a,b,c are input parameters, and x1,x2 are roots, d is discriminant
  19. {
  20. if (b == 0 )
  21. printf (" \n No roots"); // Result output
  22. else
  23.  
  24. x1 = - c/b; // Root calculation formula
  25. printf ("\n One root x1 = %lf", x1); // Result output
  26.  
  27. }
  28. else
  29. d=b*b-4*a*c; // Discriminant calculation formula
  30. if (d>0)
  31. {
  32. x1=(sqrt(d)-b)/(2*a); // Roots calculation formulas
  33. x2=(-sqrt(d)-b)/(2*a);
  34. printf("\nRoots of the equation \nx1 = %lf,\nx2 = %lf", x1,x2); // Result output
  35.  
  36. }
  37. else
  38. if (d<0)
  39. printf("\n No roots"); // Result output
  40. else
  41. if (d==0)
  42. {
  43. x1=-b/(2*a); // Root calculation formula
  44. printf("\n One root x1= %lf", x1); // Result output
  45.  
  46. }
  47.  
  48. } //get_roots(a, b, c, x1, x2, d)
  49. void main() // Main function
  50. {
  51. double a; // Senior equation coefficient
  52. double b; // Сoefficient
  53. double c; // Free member
  54. double d; // Discriminant
  55. double x1, x2; // Roots
  56.  
  57. representation(); // Call function representation()
  58.  
  59. printf("\nEnter a: "); // Input
  60. scanf("%lf", &a);
  61. printf("\nEnter b: "); // Input
  62. scanf("%lf", &b);
  63. printf("\nEnter c: "); // Input
  64. scanf("%lf", &c);
  65.  
  66. get_roots(a, b, c, x1, x2, d); // Call function get_roots(a, b, c, x1, x2, d)
  67.  
  68. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement