Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------------------------------------------------------
- // Exercise 5
- // ----------
- //
- // General : The program will get the three coefficients and it will solve the equation if its possible.
- //
- // Input : Three coefficients.
- //
- // Process : The program solves the equation according to the well known formula. In case that the equation cant be solved, the program will alert the user.
- //
- // Output : Prints the equation and its sulotion.
- //
- //------------------------------------------------------------------------------------------------------------------------------
- // Programmer: Ohad Ozcohen
- // Date: 9.9.2016
- //------------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <math.h>
- void main(void)
- {
- float a,b,c;
- float delta;
- float root1, root2;
- printf("Please enter a: ");
- scanf_s("%f", &a);
- printf("Please enter b: ");
- scanf_s("%f", &b);
- printf("Please enter c: ");
- scanf_s("%f", &c);
- delta = b*b - 4 * a*c;
- if (delta > 0)
- {
- float test = sqrt(delta);
- // sqrt() function returns square root
- root1 = (-b + sqrt(delta)) / (2 * a);
- root2 = (-b - sqrt(delta)) / (2 * a);
- printf("root1 = %.2lf and root2 = %.2lf", root1, root2);
- }
- if (delta == 0)
- {
- root1 = root2 = -b / (2 * a);
- printf("root1 = root2 = %.2f;", root1);
- }
- if (delta<0)
- {
- printf("There is no solution to the equation");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement