Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define FIO "written by\nManakina Alyona"
- #define gr "student group 833"
- #define lr7 "Laboratory work 7"
- #define stars printf("\n****************")
- void representation() // Student presentation function
- {
- stars;
- printf("\n%s\n%s\n%s", lr7, gr, FIO);
- stars;
- }
- void get_roots( double a, double b, double c, double x1, double x2, double d) // The function to calculate the roots of the equation,
- {
- if (a == 0) // where a,b,c are input parameters, and x1,x2 are roots, d is discriminant
- {
- if (b == 0 )
- printf (" \n No roots"); // Result output
- else
- x1 = - c/b; // Root calculation formula
- printf ("\n One root x1 = %lf", x1); // Result output
- }
- else
- d=b*b-4*a*c; // Discriminant calculation formula
- if (d>0)
- {
- x1=(sqrt(d)-b)/(2*a); // Roots calculation formulas
- x2=(-sqrt(d)-b)/(2*a);
- printf("\nRoots of the equation \nx1 = %lf,\nx2 = %lf", x1,x2); // Result output
- }
- else
- if (d<0)
- printf("\n No roots"); // Result output
- else
- if (d==0)
- {
- x1=-b/(2*a); // Root calculation formula
- printf("\n One root x1= %lf", x1); // Result output
- }
- } //get_roots(a, b, c, x1, x2, d)
- void main() // Main function
- {
- double a; // Senior equation coefficient
- double b; // Сoefficient
- double c; // Free member
- double d; // Discriminant
- double x1, x2; // Roots
- representation(); // Call function representation()
- printf("\nEnter a: "); // Input
- scanf("%lf", &a);
- printf("\nEnter b: "); // Input
- scanf("%lf", &b);
- printf("\nEnter c: "); // Input
- scanf("%lf", &c);
- get_roots(a, b, c, x1, x2, d); // Call function get_roots(a, b, c, x1, x2, d)
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement