Computer Science‎ > ‎

C Program: Source Code for Solving Quadratic Equations



 
The C++ Programming Language...
List Price: Rs.775
Our Price: Rs.736
Buy from FlipKart

The C++ Programming Language (Bjarne Stroustrup)

Beginning C++ Through Game Pr...
Our Price: Rs.2008
Buy from FlipKart

       
Beginning C++ through Game Programming 

 
C++ How to Program
List Price: Rs.695
Our Price: Rs.632
Buy from FlipKart

                               
 
The C Programming Language
List Price: Rs.175
Our Price: Rs.137
Buy from FlipKart

             
The C Programming Language (Kernighan)
 
C How To Program 6th  Edition
List Price: Rs.650
Our Price: Rs.624
            Buy from FlipKart


          
C How to Program (Deitel and Deitel)

 



C Program to find the roots of Quadratic Equations


/*The following program finds out the roots of a quadriatic equation by taking the coefficents as the input
from the user.*/
#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c;
printf("Enter the coefficents of the quadriatic equation of the form ax^2+bx+c\n");
scanf("%lf%lf%lf",&a,&b,&c);//We ask for the coefficents from the user
double D=pow(b,2)-4*a*c;
if(D<0)//We check the determinant whether it is greater or lesser than zero and accordingly find real or imaginary roots
{
    printf("The roots are imaginary\n");
    double real,img;
    real=(-1*b)/(2*a);//The real part of the root
    img=sqrt(-1*D)/(2*a);//The imaginary part of the root
    printf("The first root is %lf+i%lf\n",real,img);
    printf("The first root is %lf-i%lf\n",real,img);
}
if(D>=0)
{
    printf("The roots are real\n");
    if(D!=0)
{   //We find both roots if D>0
    double root1=(-1*b+sqrt(D))/(2*a);
    double root2=(-1*b-sqrt(D))/(2*a);
    printf("The first root is %lf\n",root1);
    printf("The second root is %lf\n",root2);
}
else
{   //We find the root if D==0 and display that we have equal roots
    double root=(-1*b)/(2*a);
    printf("The roots are equal\n");
    printf("The root is %lf\n",root);
}
}
getch();
}
/*A sample run of the program is found to work as follows:-
Enter the coefficents of the quadriatic equation of the form ax^2+bx+c
1 5 6
The roots are real
The first root is -2.000000
The second root is -3.000000
*/









 














C Program to Reverse A String

C Program: Building an Expression Evaluator
C Program: Check for Armstrong Numbers
C Program: Check whether a string is a Palindrome or not
C Program: Common Operations on Sets - Union, Intersection, Difference, Cardinal Product
C Program: Computing exp(x), sin(x), cos(x), tan(x) using series expansions
C Program: Computing the Area of a Circle
C Program: Computing the Upper Triangular Matrix and Lower Triangular Matrix
C Program: Demonstrating File Handling Functions
C Program: Demonstrating Operations on Matrices - Addition, Subtraction, Multiplication, Inversion, Finding Determinants
C Program: Demonstrating the use of Bitwise Operators
C Program: Displaying a Histogram of word frequencies (unigram)
C Program: Distance Vector Routing Algorithm using Bellman Ford's Algorithm
C Program: Numerical Computing - The Gaussian Elimination Method
C Program: Numerical Computing - Implementing the Newton Raphson Method
C Program: Numerical Computing - the Bisection Method
C Program: Numerical Computing - The Gaussian Elimination Technique from Linear Algebra
C Program: Numerical Computing - the Jacobi Method
C Program: Printing the Pascal Triangle
C Program: Reversing the order of words in a sentence
C Program: Solving Simultaneous Equations in Two Variables
C Program: Source Code for computing the GCD(HFC) of two numbers
C Program: Source Code for Solving Quadratic Equations
C Program: Source code to solve the Josephus Problem
C Program: Sudoku Solver
C Program: The Usage of Command Line Arguments
C Program: Using the Sieve of Eratosthenes to print Prime Numbers