C Program to find the roots of a Quadratic equation
is known as a quadratic equation, where a , b and c are numbers and a is not equal to 0 . The values of x which satisfies the equation are known as the roots of the equation.
To calculate the roots of a quadratic equation we use the following formula:
where \(\sqrt\) is called the discriminant.
If discriminant > 0 , then the equation has two distinct real roots.
If discriminant = 0 , then the roots of the equation are real and same.
If discriminant < 0 , then the roots of the equation are imaginary.
The following is a C program which computes the roots of the quadratic equation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*********************************************************** * C Program to find the roots of a Quadratic equation ************************************************************/ #include // include stdio.h #include // include math.h for mathematical functions int main() float a, b, c, discriminant, root1, root2; printf("Enter coefficient of x^2: "); scanf("%f", &a); printf("Enter coefficient of x: "); scanf("%f", &b); printf("Enter constant term: "); scanf("%f", &c); discriminant = sqrt( b*b - 4*a*c ); if(discriminant >= 0) root1 = ( -b + discriminant ) / (2.0*a); root2 = ( -b - discriminant ) / (2.0*a); printf("\nFirst root: %.2f\n", root1); printf("Second root: %.2f\n", root2); > else printf("\nRoots are imaginary"); > return 0; >
Expected Output: 1st run:
1 2 3 4 5 6
Enter coefficient of x^2: 1 Enter coefficient of x: 7 Enter constant term: 12 First root: -3.00 Second root: -4.00
1 2 3 4 5
Enter coefficient of x^2: 1 Enter coefficient of x: 4 Enter constant term: 5 Roots are imaginary
Related Programs:
- C Program to find Armstrong numbers
- C Program to find LCM and HCF of two numbers
- C Program to find the sum of natural numbers upto N terms
- C Program to reverse the digits of a number
- C Program to check whether a year is a leap year
C Programming Examples
- C Program to find the sum of digits of a number
- C Program to find the factorial of a number
- C Program to find Armstrong numbers
- C Program to find Prime Numbers
- C Program to generate Fibonacci sequence
- C Program to find the sum of the digits of a number untill the sum is reduced to a single digit
- C Program to count number of digits in a number
- C Program to reverse the digits of a number
- C Program to find the sum of natural numbers upto N terms
- C Program to check whether the number is even or odd.
- C Program to find the roots of a Quadratic equation
- C Program to print Triad Numbers
- C Program to multiply two numbers using Russian peasant method
- C Program to find the number of denominations for a given amount
- C Program to check whether the number is a Palindrome
- C Program to determine the type and Area of a Triangle
- C Program to print Twin prime numbers between two ranges
- C Program to print the two digit number in words
- C Program to calculate the power of a number
- C Program to find the largest of three numbers
- C Program to find the product of digits of a number
- C Program to calculate Permutation and Combination
- C Program to find LCM and HCF of two numbers
- C Program to find the maximum and minimum element in the array
- C Program to reverse the elements of an array
- C Program to sum the elements of an array
- C Program to find the count of even and odd elements in the array
- C Program to add two Matrices
- C Program to multiply two matrices
- C Program to find the transpose of a matrix
- C Program to search for an item using Linear Search
- C Program to search for an item using Binary Search
- C Program to sort an array in ascending order using Bubble Sort
- C Program to check whether a string is palindrome or not
- C Program to calculate Factorial using recursion
- C Program to calculate the power using recursion
- C Program to reverse the digits of a number using recursion
- C Program to convert a decimal number to binary, octal and hexadecimal using recursion
- C Program to convert a decimal number to a binary number
- C Program to convert a decimal number to a hexadecimal number
- C Program to convert a decimal number to an octal number
- C Program to Convert a Binary Number to a Decimal Number
- C Program to convert the temperature in Fahrenheit to Celsius
- C Program to convert a decimal number to Roman numerals
- C Program to print Fibonacci Sequence using recursion
- C Program to check whether a year is a leap year
- C Program to print the earlier of the two dates
- C Program to check whether a date is valid or not
- C Program to calculate the difference of two dates in years, months and days
- C Program to calculate the day of year from the date
- C Program to print the date in legal form
- C Program to print various triangular patterns
- C Program to print Pascal Triangle
- C Program to print Floyd’s Triangle
- C Program to simulate a simple calculator using switch statement
- C Program to find the student's grade
Recent Posts
- Machine Learning Experts You Should Be Following Online
- 4 Ways to Prepare for the AP Computer Science A Exam
- Finance Assignment Online Help for the Busy and Tired Students: Get Help from Experts
- Top 9 Machine Learning Algorithms for Data Scientists
- Data Science Learning Path or Steps to become a data scientist Final
- Enable Edit Button in Shutter In Linux Mint 19 and Ubuntu 18.04
- Python 3 time module
- Pygments Tutorial
- How to use Virtualenv?
- Installing MySQL (Windows, Linux and Mac)
- What is if __name__ == '__main__' in Python ?
- Installing GoAccess (A Real-time web log analyzer)
- Installing Isso