EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

Write a program to find the solutions of the given quadratic equation using function.

Source Code

#include<stdio.h>
#include<conio.h>
#include<math.h>
void quadratic(float a,float b,float c)
{
  float t,r1,r2;
  t=(b*b)-(4*a*c);
  printf("\n The roots of the quadratic equation %fx2+%fx+%f are:",a,b,c);
  if(t==0)
10    {
11      r1=(b*-1)/(2*a);
12      printf("\n only one root : %f",r1);
13    }
14    else if(t<0)
15    {
16      printf(" imaginary.");
17    }
18    else
19    {
20      r1=((b*-1)+sqrt(t))/(2*a);
21      r2=((b*-1)-sqrt(t))/(2*a);
22      printf(" %f and %f",r1,r2);
23    }
24  }
25  int main (int argc, char *argv[])
26  {
27    clrscr();
28    float a,b,c;
29    printf("\n Enter the co ordinates of the quadratic equation:");
30    printf("\n Enter the value preceding x2: ");
31    scanf("%f",&a);
32    printf("\n Enter the value preceding x: ");
33    scanf("%f",&b);
34    printf("\n Enter the numeric value: ");
35    scanf("%f",&c);
36    quadratic(a,b,c);
37    getch();
38  }

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code