Created
October 10, 2018 14:58
-
-
Save feynon/352e20fa263e684bfd14e5479c2e6c77 to your computer and use it in GitHub Desktop.
Program to find roots of quadratic expression in C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To find quadratic roots of an equation | |
#include <stdio.h> | |
#include <math.h> | |
int main() | |
{ | |
float a, b, c; | |
float d, r1, r2; | |
printf("Enter quadratic equation in the format ax^2+bx+c: "); | |
scanf("%fx^2%fx%f",&a,&b,&c); | |
d = b * b - 4 * a * c; | |
if(d < 0){ | |
printf("Roots are complex numbers.\n") | |
return 0; | |
} | |
else if(d==0){ | |
printf("Roots are equal.\n"); | |
r1 = - b / (2 * a); | |
printf("Roots of quadratic expression is: %.3f "r1); | |
} | |
else{ | |
printf("Roots are real numbers.\n"); | |
r1 = (-b + sqrt(d)) / 2 * a); | |
r2 = (-b - sqrt(d)) / 2 * a); | |
printf("Roots of the equation are: %.3f ,%.3f" r1, r2); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please debug and correct the given code and paste the same on paste https://hastebin.com,Thanks! I'm live @ankeshb8 on twitter.