700 likes | 887 Views
Program structure. Examples Rules More examples. Program structure. Transfering the problem into code. Split the problem into smaller problems. Make a structure of the problems (indata/outdata). Write down an operationlist and the conditions. ?. Program structure.
E N D
Program structure • Examples • Rules • More examples
Program structure Transfering the problem into code • Split the problem into smaller problems • Make a structure of the problems (indata/outdata) • Write down an operationlist and the conditions ?
Program structure Transfering the problem into code • Split the problem into smaller problems • Make a structure of the problems (indata/outdata) • Write an operationslist and the conditions ? • Pseudocode can be used
What is pseudocode? • Pseudocode is a combination between • ordinary language and real programcode • The pseudocode includes the sequences, • selections, iterations, conditions and operations • placed in the structurediagram • Pseudocode can be used to simplify the • structured problem before it becomes • real programcode
Milk the cow - Pseudocode Peasant needs money
2 1 3 IF peasant_tired = yes ELSE By machine By hand WHILE milk = exist WHILE milk = exist * * Squeeze Squeeze 4 5 6 7 Milk the cow - Pseudocode Peasant needs money Operationlist Milk the cow 1. Input peasant_tired value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. While milk = exist
2 Milk the Sell milk 8 Operationlist cow 3 9 8. Input neighbour_home value 9. Read selection (neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value ELSE To neighbours To village 10 11 12 12 6 7 Conditionlist 4. If neighbour_home = yes Milk the cow - Pseudocode Peasant needs money IFneighbour_home = yes ELSE By hand WHILE milk = exist * Squeeze
Spend money 8 Operationlist 9 13. Buy clothes 14. Read money value ELSE WHILE money = exist * Buy clothes To neighbours To village for wife 13 14 10 11 12 12 Conditionlist 5. While money = exist Milk the cow - Pseudocode Peasant needs money Sell milk If neighbour _home
Milk the Sell milk Spend money cow IF neighbour_home = yes ELSE IF peasant_tired = yes WHILE money = exist ELSE * To neighbours To village Buy clothes By machine By hand for wife WHILE milk = exist WHILE milk = exist * * Squeeze Squeeze Milk the cow - Pseudocode Peasant needs money
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 4. If neighbour_home = yes 5. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 4. If neighbour_home = yes 5. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 4. If neighbour_home = yes 5. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
OK! How about some real programcoding? PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist
C Solving 2nd degree equations • Structure diagram • Structure diagram to pseudocode • Pseudocode to C programming
y = ax +bx +c 0 = ax +bx +c 2 2 2nd degree equation Solving 2nd degree equations Program structure D
0 = ax +bx +c 2 Solving 2nd degree equations Program structure 2nd degree equation Information
0 = ax +bx +c 2 Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation
0 = ax +bx +c 2 Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation Constant a Constant b Constant c Possible solution
0= ax +bx +c 2 D = b²/(4a²)-c/a Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation Constant a Constant b Constant c Possible solution If D ³ 0 Solution No real solution
0 = ax +bx +c 2 D = b²/(4a²)-c/a Solution No real solution Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation Constant a Constant b Constant c Possible solution If D ³ 0 If D = 0 Two solutions One solution
0 = ax +bx +c 2 Solve equation? D = b²/(4a²)-c/a While answer ¹ n or N * One equation Solution No real solution Solving 2nd degree equations Program structure 2nd degree equation Information 2 1 Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 If D = 0 11 Two solutions One solution 7 9 8 10
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Rotate and Flip Solving equations Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding
Solution No real solution Rotate and Flip Solving equations Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding Constant a 3 Information 1 2nd degree equation 2 Constant b 4 Solve equation? One equation * While answer ¹ n or N Constant c 5 7 If D = 0 One solution 6 If D ³ 0 8 Time 9 Two solutions Possible solution 10 11 2 Division
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or NInput constant aInput constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or NInput constant aInput constant bInput constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant ccalculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/aIf D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a)display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display xelse calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x elsecalculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖDdisplay x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end ifelse display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if elsedisplay No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end ifAsk if user would like to solve an equation (y/n)end while Pseudo coding
2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding
C Solving equations Here’s an example of translating the pseudocode to C code Program