Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. C Programming

Solving Quadratic Equation

Book navigation

  • C Programming Introduction
  • C – Program Code – Basics Part I
  • C – Program Code – Basics Part II
  • Operators in C Programming
  • C – Program Code – Basics Part III
  • C Program Code Basics - Part IV
  • Addition , Subtraction and Multiplication of Matrices
  • Solving Quadratic Equation
  • Sum of sin series
  • Sum of cos series
  • Sum of e series
  • Ascending and Descending order
  • Sorting in Alphabetical Order
  • Factorial of a number
  • Fibonacci Series
  • String Counting
  • String Manipulation
  • Bisection Method
  • Newton Raphson Method
  • Lagrange's Interpolation
By Karthikeyan , 5 September, 2009

C Sample Program : Solving Quadratic Equation. This program receives the coefficient of a quadratic equation and calculates output


#include 
#include
#include  
main()
   {
      float  a, b, c, d,/*d for discriminant*/
             root1, root2;
	
	  printf("\nInput values of a, b, and c\n");
      scanf("%f %f %f", &a, &b, &c);

      d = b*b - 4*a*c ;

      if(d < 0)
      {
         printf("\n\nROOTS ARE IMAGINARY\n");
         root1 = -b /(2*a);
         root2 = sqrt(-d)/(2*a);
         printf("\nThe Real part      Root1 = %5.2f", root1);
         printf("\nThe imaginary part Root2 = %5.2f",root2);
      }
      else if(d == 0)
      {
        printf("\n THE ROOTS ARE REAL AND EQUAL");
        root1 = -b / (2*a);
        root2 = -b / (2*a);
        printf("\n Root1 = %f\n Root2 = %f",root1, root2);
      }
      else
      {
         root1 = (-b + sqrt(d))/(2.0*a);
         root2 = (-b - sqrt(d))/(2.0*a);
         printf("The ROOTS ARE REAL AND UNEQUAL \n");
         printf("\n\nRoot1 = %5.2f\n\nRoot2 = %5.2f\n",
                     root1,root2 );
	   }
	
   }
  • Add new comment

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy