Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.11 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)   // The function to calculate the roots of the equation,
  17.     double x1,x2,d;
  18. {
  19.    if (a == 0)                                                                  // where a,b,c are input parameters, and x1,x2 are roots, d is discriminant
  20.     {
  21.         if (b == 0 )
  22.         printf (" \n No roots");                                                // Result output
  23.         else
  24.        
  25.          x1 = - c/b;                                                            // Root calculation formula
  26.          printf ("\n One root x1 = %lf", x1);                                   // Result output
  27.        
  28.     }
  29.     else
  30.         d=b*b-4*a*c;                                                            // Discriminant calculation formula
  31.         if (d>0)
  32.             {
  33.                 x1=(sqrt(d)-b)/(2*a);                                           // Roots calculation formulas
  34.                 x2=(-sqrt(d)-b)/(2*a);
  35.                 printf("\nRoots of the equation \nx1 = %lf,\nx2 = %lf", x1,x2); // Result output
  36.            
  37.             }
  38.         else
  39.             if (d<0)
  40.                 printf("\n No roots");                                          // Result output
  41.             else
  42.                 if (d==0)
  43.                 {
  44.                     x1=-b/(2*a);                                                // Root calculation formula
  45.                     printf("\n One root x1= %lf", x1);                          // Result output
  46.                
  47.                 }
  48.    
  49. } //get_roots(a, b, c, x1, x2, d)
  50. void main()                                                                     // Main function
  51. {
  52.     double a;                                                                   // Senior equation coefficient
  53.     double b;                                                                   // Сoefficient
  54.     double c;                                                                   // Free member
  55.     double d;                                                                   // Discriminant
  56.     double x1, x2;                                                              // Roots
  57.    
  58.     representation();                                                           // Call function representation()
  59.    
  60.     printf("\nEnter a: ");                                                      // Input
  61.     scanf("%lf", &a);
  62.     printf("\nEnter b: ");                                                      // Input
  63.     scanf("%lf", &b);
  64.     printf("\nEnter c: ");                                                      // Input
  65.     scanf("%lf", &c);
  66.    
  67.     get_roots(a, b, c);                                              // Call function  get_roots(a, b, c, x1, x2, d)
  68.    
  69. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement