answersLogoWhite

0


Best Answer

Dim a, b, c, undroot, root, posx, negx, x1, x2 As Single

Private Sub cmdcompute_Click()

a = txta.Text

b = txtb.Text

c = txtc.Text

If txta.Text = "" Then

MsgBox "Please enter the value of A ", 0 + 32

Exit Sub

End If

If txtb.Text = "" Then

MsgBox "Please enter the value of B ", 0 + 32

Exit Sub

End If

If txtc.Text = "" Then

MsgBox "Please enter the value of C ", 0 + 32

Exit Sub

End If

If a = 0 Then

MsgBox "A can't equal 0 ", 0 + 32

Exit Sub

End If

If (b ^ 2) - 4 * a * c < 0 Then

txtx1.Text = ""

txtx2.Text = ""

MsgBox "Imaginary solution : (b^2)-4*a*c < 0", 0 + 48

Exit Sub

End If

'Calcualtions

undroot = (b ^ 2) - 4 * a * c

root = undroot ^ (0.5)

posx = (b * -1) + root

negx = (b * -1) - root

x1 = posx / (2 * a)

x2 = negx / (2 * a)

'Displaying results

txtx1.Text = " " & x1

txtx2.Text = " " & x2

End Sub

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Vb program to find roots of quadratic equation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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*/


The degree of a quadratic equation?

The Quadratic Formula song: (my grade saver) To the tune of the jack in the box song X equals negative B plus or minus square root of B squared minus 4AC all over 2A :)


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 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


Write a program to solve a quadratic equation using the quadratic formula in c plus plus?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { float a,b,c,z,d,x,y; clrscr(); printf("Enter the value of a,b,c"); scanf("%f %f %f",&amp;a,&amp;b,&amp;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&lt;stdio.h&gt; #include&lt;math.h&gt; 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", &amp;a); printf("\n"); printf("b = "); scanf("%f", &amp;b); printf("\n"); printf("c = "); scanf("%f", &amp;c); printf("\n"); dis = (b*b-4*a*c); if(dis &lt; 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"); }

Related questions

Write an algorithm to find the root of quadratic equation?

Write an algorithm to find the root of quadratic equation


Why do mathmaticians use the quadratic formula?

To find the roots (solutions) of a quadratic equation.


What is the formula to find the product of the roots of a quadratic equation?

If the quadratic is ax2 + bx + c = 0 then the product of the roots is c/a.


When do you use the quadratic formula?

When you need to find the roots of a quadratic equation and factorisation does not work (or you cannot find the factors). The quadratic equation ALWAYS works. And when appropriate, it will give the imaginary roots which, judging by this question, you may not yet be ready for.


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.


How do you find the sum of the roots of the equation x2 plus 5x plus 9 equals 0?

This quadratic equation has no real roots because its discriminant is less than zero.


What are the roots of the polynomial x2 plus 3x plus 5?

You can find the roots with the quadratic equation (a = 1, b = 3, c = -5).


What is the quadratic formula used forHow do you find the average of a set of numbers?

The quadratic formula is used to find the solutions (roots) of a quadratic equation in the form ax² + bx + c = 0, where &quot;a,&quot; &quot;b,&quot; and &quot;c&quot; are constants.


What does quadratic formulas look like?

ax2 +bx + c To find roots of any quadratic equation. X = - b (+/-) sqrt(b2 - 4ac)/2a


How you find the solution of a quadratic equation by graphing its quadratic equation?

When you graph the quadratic equation, you have three possibilities... 1. The graph touches x-axis once. Then that quadratic equation only has one solution and you find it by finding the x-intercept. 2. The graph touches x-axis twice. Then that quadratic equation has two solutions and you also find it by finding the x-intercept 3. The graph doesn't touch the x-axis at all. Then that quadratic equation has no solutions. If you really want to find the solutions, you'll have to go to imaginary solutions, where the solutions include negative square roots.


What is an application for a quadratic equation in real life?

A quadratic equation could be used to find the optimal ingredients for a mixture. Example: if you are trying to create a super cleanser, you could make a parabola of your ingredients, finding the roots of the equation to find the optimal amount for each ingredient.


What 2 values of x are roots of the polynomial x2 plus 3x-5?

You can find the roots with the quadratic equation (a = 1, b = 3, c = -5).