answersLogoWhite

0


Best Answer

#include<stdio.h> #include<conio.h>

void main()

{

float a,b,c,z,d,x,y;

clrscr();

printf("Enter the value of a,b,c");

scanf("%f %f %f",&a,&b,&c);

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

z=sqrt(d);

x=(-b+z)/(2*a);

y=(-b+z)/(2*a);

printf("The Quadratic equation is x=%f and y=%f",x,y);

getch();

}

This answer does not think about imaginary roots. I am a beginner in C Programming. There might be flaws in my code. But, it does well.

the code is

#include<stdio.h>

#include<math.h>

main()

{

float a, b, c;

float dis, sqdis, real, imag, root1, root2;

printf("This program calculates two roots of quadratic equation of the form ax2+bx+c=0.\n");

printf("\n");

printf(" please type the coefficients a, b and c\n");

printf("\n");

printf("a = ");

scanf("%f", &a);

printf("\n");

printf("b = ");

scanf("%f", &b);

printf("\n");

printf("c = ");

scanf("%f", &c);

printf("\n");

dis = (b*b-4*a*c);

if(dis < 0)

{

sqdis = sqrt(-dis);

real = -b/(2*a);

imag = sqdis/(2*a);

printf(" The roots of the quadratic equations are \n x1\t=\t %f + %f i\n x2\t=\t %f -

%f i\n", real, imag, real, imag);

}

else

{

sqdis = sqrt(dis);

root1 = -b/(2*a)+sqdis/(2*a);

root2 = -b/(2*a)-sqdis/(2*a);

printf("The two roots of the quadratic equations are %f and %f.\n", root1, root2);

}

system("pause");

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

/*---------------------------------------------------------------------------

PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION

---------------------------------------------------------------------------*/

#include

#include

#include

int main()

{

int A,B,C;

float disc,deno,x1,x2;

printf("\n-------------------------------------------------------");

printf("\n\n PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION ");

printf("\n\n-------------------------------------------------------");

printf("\n\n\t ENTER THE VALUES OF A,B,C...");

scanf("%d,%d,%d",&A,&B,&C);

disc = (B*B)-(4*A*C);

deno = 2*A;

if(disc > 0)

{

printf("\n\t THE ROOTS ARE REAL ROOTS");

x1 = (-B/deno)+(sqrt(disc)/deno);

x2 = (-B/deno)-(sqrt(disc)/deno);

printf("\n\n\t THE ROOTS ARE...: %f and %f\n",x1,x2);

}

else if(disc == 0)

{

printf("\n\t THE ROOTS ARE REPEATED ROOTS");

x1 = -B/deno;

printf("\n\n\t THE ROOT IS...: %f\n",x1);

}

else

printf("\n\t THE ROOTS ARE IMAGINARY ROOTS\n");

printf("\n-------------------------------------------------------");

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include

#include

#include

void main()

{

int a,b,c,d;

float x1,x2,x,realp,imp;

clrscr();

printf("Enter the values of a,b & c:\n");

scanf("%d %d %d",&a,&b,&c);

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

if(d>0)

{

x1=-b+sqrt(d)/(2*a);

x2=-b-sqrt(d)/(2*a);

printf("\nThe Roots are real and not equal");

printf("\nThe roots are........x1=%f x2=%f",x1,x2);

}

else if(d==0)

{

x=-b/(2*a);

printf("\nThe roots are real and repeated");

printf("\nHence the repeated root x is %f",x);

}

else

{

realp=sqrt(abs(d))/(2*a);

imp=sqrt(abs(d))/(2*a);

printf("\nThe roots are complex or imaginary ");

printf("\n root1=%f+i%f",realp,imp);

printf("\n root2=%f-i%f",realp,imp");

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include
#include

using std::cin;
using std::cout;

int main()
{
cout << endl << "This program find real roots of a*x*x + b*x + c = 0";

double a = 0.0;
cout << endl << "Enter a: ";
cin >> a;

double b = 0.0;
cout << endl << "Enter b: ";
cin >> b;

double c = 0.0;
cout << endl << "Enter c: ";
cin >> c;

double det = b*b - 4*a*c;
double x1 = 0.0;
double x2 = 0.0;
if (det >= 0.0)
{
if (a == 0.0)
{
cout << endl << "It's a linear system with solution: ";
if (b != 0.0)
{
x1 = -c/b;
cout << x1;

}
else
{
cout << "System is not correct!";
return 1;

}

}
else
{
x1 = (-b + sqrt(det))/(2*a);
cout << endl << "Rirst root is: " << x1;

x2 = (-b - sqrt(det))/(2*a);
cout << endl << "Second root is: " << x2;

}

}
else
{
cout << endl << "There are no real roots!";

}

system("PAUSE");
return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago
  1. # include
  2. # include
  3. # include
  4. void main()
  5. {
  6. float a, b, c, d, real, imag, r1, r2, n ;
  7. int k ;
  8. clrscr() ;
  9. printf("Enter the values of A, B & C : ") ;
  10. scanf("%f %f %f", &a, &b, &c) ;
  11. if(a != 0)
  12. {
  13. d = b * b - 4 * a * c ;
  14. if(d < 0)
  15. k = 1 ;
  16. if(d == 0)
  17. k = 2 ;
  18. if(d > 0)
  19. k = 3;
  20. switch(k)
  21. {
  22. case 1 :
  23. printf("\nRoots are imaginary\n") ;
  24. real = - b / (2 * a) ;
  25. d = - d ;
  26. n = pow((double) d, (double) 0.5) ;
  27. imag = n / (2 * a) ;
  28. printf("\nr1 = %7.2f + j%7.2f", real, imag) ;
  29. printf("\nr2 = %7.2f - j%7.2f", real, imag) ;
  30. break ;
  31. case 2 :
  32. printf("\nRoots are real and equal\n") ;
  33. r1 = - b / (2 * a) ;
  34. printf("\nr1 = r2 = %7.2f", r1) ;
  35. break ;
  36. case 3 :
  37. printf("\nRoots are real and unequal\n") ;
  38. r1 = (- b + sqrt((double) d)) / (2 * a) ;
  39. r2 = (- b - sqrt((double) d)) / (2 * a) ;
  40. printf("\nr1 = %7.2f",r1) ;
  41. printf("\nr2 = %7.2f",r2) ;
  42. break ;
  43. }
  44. }
  45. else
  46. printf("\nEquation is linear") ;
  47. getch() ;
  48. }
This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include

void main()

{

float a,b,c,z,d,x,y;

printf("Enter the value of a,b,c");

scanf("%f %f %f",&a,&b,&c);

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

z=sqrt(d);

x=(-b+z)/(2*a);

y=(-b+z)/(2*a);

printf("The Quadratic equation is x=%f and y=%f",x,y);

}

Read more: http://wiki.answers.com/Write_a_program_in_c_programming_language_that_computes_the_roots_of_the_quadratic_equation_ax2_bx_c#ixzz1Uuc5ZW4a

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The most straightforward way to do this is to use the quadratic equation.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to solve a quadratic equation using the quadratic formula in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program to find the square root of the quadratic equation using flow chart?

You don't need a flow chart for that; just use the quadratic formula directly; most programming languages have a square root function or method. You would only need to do this in many small steps if you use Assembly programming. The formulae would be something like this: x1 = (-b + sqrt(b^2 - 4*a*c)) / (2 * a) and x2 = (-b - sqrt(b^2 - 4*a*c)) / (2 * a) where a, b, and c are the coefficients of the quadratic equation in standard form, and x1 and x2 are the solutions you want.


Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. &lt;&lt;&gt;&gt; The determinant of a singular matix is zero.


Write a c program to find the roots of a quadratic equation using if else?

/*Hello!! I'm aditya From Bangalore I have the solution of this program*/ #include &lt;stdio.h&gt; #include &lt;math.h&gt; main() { float a,b,c,x1,x2,delta=0; printf("enter the value of a,b,c\n"); scanf("f%f",&amp;a,&amp;b,&amp;c); delta=((b*b)-(4ac)); if(a=0) { printf("the variables cannot form a quadratic equation\n"); } else { x1=(-b)+(sqrt(((b*b)-(4ac))/2a)) x2=(-b)-(sqrt(((b*b)-(4ac))/2a)) } if(delta=0) { printf("the roots are real and equal"); } if(delta&gt;0) { printf("the roots are real and distinct"); } if(delta&lt;0) { printf("the roots are imaginary"); x1=(-b)+(sqrt(((b*b)-((4ac))/(float)(2a)) x2=(-b)-(sqrt(((b*b)-((4ac))/(float)(2a)) } printf("the roots of the equation are %2.2f\n",x1,x2,delta); } /*the program is written by using simple-if and if-else constructs*/


Write a Qbasic program to find the root of a quadratic equation using the formula if the result is less than 0 the program should print the root are immerginary and end the program?

(Uses Square Root Function) PRINT "Ax^2 + Bx + C = 0" INPUT "A = ", A INPUT "B = ", B INPUT "C = ", C D = B * B - 4 * A * C IF D &gt; 0 THEN DS = SQR(D) PRINT "REAL ROOTS:", (-B - D) / (2 * A), (-B + D) / (2 * A) ELSE IF D = 0 THEN PRINT "DUPLICATE ROOT:", (-B) / (2 * A) ELSE DS = SQR(-D) PRINT "COMPLEX CONJUGATE ROOTS:", (-B / (2 * A)); "+/-"; DS / (2 * A); "i" END IF END IF


How to write program for secant method in mathematica?

How to write a program for secant method by mathematica

Related questions

Algorithm to find the roots of a quadratic equation?

The easiest way to write a generic algorithm is to simply use the quadratic formula. If it is a computer program, ask the user for the coefficients a, b, and c of the generic equation ax2 + bx + c = 0, then just replace them in the quadratic formula.


Write an algorithm to find the root of quadratic equation?

Write an algorithm to find the root of quadratic equation


What are all the ways you can solve a quadratic equation?

First, write the equation in standard form, i.e., put zero on the right. Then, depending on the case, you may have the following options:Factor the polynomialComplete the squareUse the quadratic formula


How do you write a program to solve a quadratic equation which has upto power 2 for example xto power 2 plus product of and x subtract 3 equals to 0?

to solve ax2 + bx + c use the quadratic formula: (-b +/-(b2 - 4ac))/2a. Programming this should be a doddle.


How did you write each quadratic equation in standard form?

readuse the answer


How do you write a poem on the roots of the quadratic equation?

2000X=Y2KoverZzz?


Write a program in C programming language that computes the roots of the quadratic equation ax2 plus bx plus c?

Write your program and if you are having a problem post it here with a description of the problem you are having. What you are asking is for someone to do your homework for you.


How would you go about solving a quadratic equation?

Write the quadratic equation in the form ax2 + bx + c = 0 then the roots (solutions) of the equation are: [-b &plusmn; &radic;(b2 - 4*a*c)]/(2*a)


How do you write a pseudo code for find the quadratic equation?

computer scince


How do you write a quadratic equation in standard form?

ax2 + bx + c


How do you write a quadratic formula?

ax2 + bx + c = y


When the roots are equal of a quadratic equation?

Write the quadratic equation in the form ax2 + bx + c = 0 The roots are equal if and only if b2 - 4ac = 0. The expression, b2-4ac is called the [quadratic] discriminant.