Program to Find Roots of a Quadratic Equation

c roots of quadratic eon 5 years, 3 months ago
#include <stdio.h> #include <math.h> int main() { double a, b, c, discriminant, root1, root2, realPart, imaginaryPart; printf("Enter coefficients a, b and c: "); scanf("%lf %lf %lf",&a, &b, &c); discriminant = b*b-4*a*c; // condition for real and different roots if (discriminant > 0) { // sqrt() function returns square root root1 = (-b+sqrt(discriminant))/(2*a); root2 = (-b-sqrt(discriminant))/(2*a); printf("root1 = %.2lf and root2 = %.2lf",root1 , root2); } //condition for real and equal roots else if (discriminant == 0) { root1 = root2 = -b/(2*a); printf("root1 = root2 = %.2lf;", root1); } // if roots are not real else { realPart = -b/(2*a); imaginaryPart = sqrt(-discriminant)/(2*a); printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imaginaryPart, realPart, imaginaryPart); } return 0; }
866
Posted By
Tower of Hanoi in C
#include <stdio.h> 
void towerOfHanoi(int n, char from_rod, 
{ 
tower of hanoi c
Reshma
Program to print half pyramid using *
#include<stdio.h>
int main()
{
half pyramid c
Reshma
Program to print half pyramid using numbers
#include <stdio.h>
int main()
{
half pyramid using numbers c
Reshma
Armstrong Number in C
#include <stdio.h>
#include <math.h>
void main()
armstrong number c
Reshma
Program to print half pyramid using alphabets
#include <stdio.h>
int main()
{
pyramid alphabets c
Reshma
Inverted half pyramid using *
#include <stdio.h>
int main()
{
inverted pyramid c
Reshma
GCD Using for loop and if Statement
#include <stdio.h>
int main()
{
gcd c
Reshma
GCD Using while loop and if...else Statement
#include <stdio.h>
int main()
{
gcd while c
Reshma
GCD for both positive and negative numbers
#include <stdio.h>
int main()
{
gcd c
Reshma
LCM using while Loop and if Statement
#include <stdio.h>
int main()
{
c lcm
Reshma
LCM Calculation by Finding GCD
#include <stdio.h>
int main()
{
c lcm using gcd
Reshma
Sum of Natural Numbers Using Recursion
#include <stdio.h>
int addNumbers(int n);
int main()
c sum of numbers
Reshma
Display Prime Numbers Between two Intervals
#include <stdio.h>
int main()
{
interval c prime
Reshma
Integer as a Sum of Two Prime Numbers
#include <stdio.h>
int checkPrime(int n);
int main()
prime numbers integer sum c
Reshma