Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- // function declarations
- void Roots (float a,float b,float delta);
- int main (void)
- {
- //Local Declarations
- float a,b,c,delta;
- printf("Input coefficient a.\n");
- scanf("%f", &a);
- printf("Input coefficient b.\n");
- scanf("%f", &b);
- printf("Input coefficient c.\n");
- scanf("%f", &c);
- printf("\nThe equation is : %0.2fx^2 + %0.2fx + %0.2f\n\n", a, b, c);
- delta = (b*b) - (4.0 * a * c);
- if (delta > 0){
- printf("There are two distinct roots.\n\n");
- Roots(a,b,delta);
- }else if (delta == 0) {
- printf("This equation has repeated roots\n\n");
- Roots(a,b,delta);
- }else if (delta < 0.0){
- printf("There are no real roots\n");
- }
- return 0;
- }
- void Roots (float a,float b,float delta)
- {
- float xOne;
- float xTwo;
- float deltaRoot;
- deltaRoot = sqrt(delta);
- xOne = (-b + deltaRoot) / (2*a);
- xTwo = (-b - deltaRoot) / (2*a);
- printf("%.2f , ", xOne);
- printf("%.2f", xTwo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement