It seems like this topic has veered way off.
#1: What is an algorithm?[INDENT]An 'algorithm' is an effective method for solving a problem expressed as a finite sequence of instructions
( http://en.wikipedia.org/wiki/Algorithm )
An algorithm can be expressed by: natural language (see example below), flow charts, psuedocode, control tables, etcetera.[/INDENT]
#2 How do I go about writing an algorithm?[INDENT]Let's go about writing a basic algorithm for the problem you wrote:
A quadratic equation can be written in the form, Ax2+Bx+C=0. Develop an algorithm and draw a flowchart to read the coefficients of A, B, and C. Calculate the roots and print out.** You should have an understanding of the quadratic equation before beginning this.
Okay, first lets start by listing the inputs and outputs we need to solve our problem.
Wait!!!! What is an input and an output!?
Well, an input is information we need to gather in order to process our problem, this is information supplied by the person who wants you to solve their problem, for the purpose of this problem our inputs will be the A, B, and C coefficients. An output is the information that we give back to the person as we process the problem. For this problem our outputs will be the two roots.
Quadratic Equation Algorithm (Natural Language: English)
--------------------------------------------------------
Inputs: A coefficient, B coefficient, C coefficient
Outputs: first root, second root
Now that we have our inputs and outputs we will begin processing our problem. Remember were not actually trying to do any of the math right now, we are just writing out the steps needed to solve the problem!
Let's start by collecting our inputs:Quadratic Equation Algorithm (Natural Language: English)
--------------------------------------------------------
Inputs: A coefficient, B coefficient, C coefficient
Outputs: first root, second root
1) Request that the user input the A coefficient.
-> Store the A coefficient for later use.
2) Request that the user input the B coefficient.
-> Store the B coefficient for later use.
3) Request that the user input the C coefficient.
-> Store the C coefficient for later use.
Now that we have all of our inputs (coefficients) stored (written down) we can begin processing our problem. Let's do this by finding our first root using the quadratic equation.Quadratic Equation Algorithm (Natural Language: English)
--------------------------------------------------------
Inputs: A coefficient, B coefficient, C coefficient
Outputs: first root, second root
1) Request that the user input the A coefficient.
-> Store the A coefficient for later use.
2) Request that the user input the B coefficient.
-> Store the B coefficient for later use.
3) Request that the user input the C coefficient.
-> Store the C coefficient for later use.
4) Set up the first root equation: ((-B + SquareRoot(B^2 - 4AC)) / (2A))
-> Process the equation and store the result as the first root for later use.
Now to get the second root!Quadratic Equation Algorithm (Natural Language: English)
--------------------------------------------------------
Inputs: A coefficient, B coefficient, C coefficient
Outputs: first root, second root
1) Request that the user input the A coefficient.
-> Store the A coefficient for later use.
2) Request that the user input the B coefficient.
-> Store the B coefficient for later use.
3) Request that the user input the C coefficient.
-> Store the C coefficient for later use.
4) Set up the first root equation: ((-B + SquareRoot(B^2 - 4AC)) / (2A))
-> Process the equation and store the result as the first root for later use.
5) Set up the second root equation: ((-B - SquareRoot(B^2 - 4AC)) / (2A))
-> Process the equation and store the result as the second root for later use.
Now that we have both of the roots we can "print out" our outputs to the person. Since I don't have a square root symbol on my keyboard I used the expression SquareRoot.Quadratic Equation Algorithm (Natural Language: English)
--------------------------------------------------------
Inputs: A coefficient, B coefficient, C coefficient
Outputs: first root, second root
1) Request that the user input the A coefficient.
-> Store the A coefficient for later use.
2) Request that the user input the B coefficient.
-> Store the B coefficient for later use.
3) Request that the user input the C coefficient.
-> Store the C coefficient for later use.
4) Set up the first root equation: ((-B + SquareRoot(B^2 - 4AC)) / (2A))
-> Process the equation and store the result as the first root for later use.
5) Set up the second root equation: ((-B - SquareRoot(B^2 - 4AC)) / (2A))
-> Process the equation and store the result as the second root for later use.
6) Display both root solutions to the user.
[/INDENT]
With this type of problem you can pretty much go with a straight list of steps; however, with more complex problems come more complex algorithms. You may not always be able to go with a straight list and this is why flow charts and control tables are great. I hope that this helped you a bit.
-- Vexx