examples rules more examples program structure transfering the problem into code split the problem...
TRANSCRIPT
![Page 1: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/1.jpg)
• Examples
• Rules
• More examples
Program structureProgram structure
![Page 2: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/2.jpg)
Program structureProgram structureTransfering 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
?
![Page 3: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/3.jpg)
Program structureProgram structureTransfering 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
?
![Page 4: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/4.jpg)
What is pseudocode? What is pseudocode?
• Pseudocode is a combination between ordinary language and real programcode
• The pseudocode includes the sequences,selections, iterations, conditions and operationsplaced in the structurediagram
• Pseudocode can be used to simplify thestructured problem before it becomes real programcode
![Page 5: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/5.jpg)
Milk the cow - Milk the cow - PseudocodePseudocodePeasant needs
money
![Page 6: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/6.jpg)
Milk the cow - Milk the cow - PseudocodePseudocodePeasant needs
money
Milk thecow
Operationlist
Conditionlist
1. Input peasant_tired value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
1. If peasant_tired = yes (sel bm)2. While milk = exist3. While milk = exist
1
By machine By hand
IF peasant_tired= yes
ELSE
Squeeze Squeeze* *WHILE milk = exist
WHILE milk = exist
4 5 6 7
2 3
![Page 7: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/7.jpg)
Milk the cow - Milk the cow - PseudocodePseudocodePeasant needs
money
Milk thecow
By hand
ELSE
Squeeze*WHILE milk = exist
6 7
IFneighbour_home = yes
Operationlist
Conditionlist
8. Input neighbour_home value9. Read selection (neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
4. If neighbour_home = yes
Sell milk
To neighbours To village
ELSE
10 12 11 12
2 3 98
![Page 8: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/8.jpg)
Milk the cow - Milk the cow - PseudocodePseudocodePeasant needs
Operationlist
Conditionlist
13. Buy clothes14. Read money value
5. While money = exist
Spend money
Buy clothesfor wife
* WHILE money = existTo neighbours To village
ELSE
money
If neighbour _home
Sell milk
10 12 1211 1413
98
![Page 9: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/9.jpg)
Milk the cow - Milk the cow - PseudocodePseudocodePeasant needs
money
Milk thecow
Sell milk
By machine By hand
IF peasant_tired = yes
ELSE
Squeeze Squeeze* *WHILE milk = exist
WHILE milk = exist
IF neighbour_home = yes
To neighbours To village
ELSE
Spend money
Buy clothesfor wife
*WHILE money = exist
![Page 10: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/10.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 11: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/11.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist4. If neighbour_home = yes5. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 12: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/12.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist4. If neighbour_home = yes5. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 13: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/13.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist4. If neighbour_home = yes5. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 14: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/14.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 15: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/15.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 16: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/16.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 17: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/17.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 18: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/18.jpg)
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
![Page 19: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/19.jpg)
PEASANT NEEDS MONEY
Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIFInput 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 ENDIFInput money value WHILE money = exist Buy clothes for wife
Read money value ENDWHILE
PseudocodePseudocode
1. If peasant_tired = yes (sel bm)2. While milk = exist3. If neighbour_home = yes4. While money = exist
Conditionlist
13. Buy clothes14. Read money value
8. Input neighbour_home value9. Read selection(neighbour/village)10. Sell to neighbours11. Sell to village 12. Input money value
1. Input peasant value2. Read selection (hand/machine)3. Input milk value4. Squeeze5. Read milk value6. Squeeze7. Read milk value
Operationlist
OK!How about some real programcoding?
![Page 20: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/20.jpg)
The endpart 2
![Page 21: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/21.jpg)
• Structure diagram
• Structure diagram to pseudocode
• Pseudocode to C programming
Solving 2nd degree equationsSolving 2nd degree equations
C
![Page 22: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/22.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
y = ax +bx +c2
2nd degree equation
0
04 4
02 4
2 4
2 4
2 4
2
2
2
2
2
22
2
22
2
2
2
2
2
a xb
ax
c
a
xb
ax
b
a
b
a
c
a
xb
a
b
a
c
a
xb
a
b
a
c
a
xb
a
b
a
c
a
xb
a
b
a
c
a
( )
( )
( )
( )
0 = ax +bx +c2
D
![Page 23: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/23.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
0 = ax +bx +c2
Information
2nd degree equation
![Page 24: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/24.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
0 = ax +bx +c2
Solve equation?
One equation*While answer n or N
Information
2nd degree equation
![Page 25: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/25.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
0 = ax +bx +c2
Possible solution
Solve equation?
One equation*While answer n or N
Information
Constant a Constant cConstant b
2nd degree equation
![Page 26: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/26.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
0= ax +bx +c2
Possible solution
Solve equation?
One equation*While answer n or N
Information
Constant a Constant cConstant b
If D 0
Solution No real solution
D = b²/(4a²)-c/a
2nd degree equation
![Page 27: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/27.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
0 = ax +bx +c2
Possible solution
Solve equation?
One equation*While answer n or N
Information
Constant a Constant cConstant b
If D 0
Solution No real solution
One solution
If D 0
Two solutions
D = b²/(4a²)-c/a
2nd degree equation
![Page 28: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/28.jpg)
Solving 2nd degree equationsSolving 2nd degree equationsProgram structure
0 = ax +bx +c2
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
D = b²/(4a²)-c/a
![Page 29: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/29.jpg)
Solving equationsSolving equations
Pseudo coding
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
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
Rotate and Flip
![Page 30: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/30.jpg)
Solving equationsSolving equations
Pseudo coding
Pos
sib
le s
olu
tion
2n
d d
eg
ree
eq
uatio
n
Sol
ve e
qua
tion
?
One
eq
uatio
n*
Whi
le a
nsw
er
n o
r N
Info
rma
tion
1
Con
sta
nt a
3
Con
sta
nt c
5
Con
sta
nt b
4If
D
0
Sol
utio
nN
o re
al s
olu
tion
11
2
2
One
so
lutio
n
If D
0 7
86
910T
wo
so
lutio
ns
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
Rotate and Flip
DivisionDivision
TimeTime
![Page 31: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/31.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 32: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/32.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 33: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/33.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 34: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/34.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 35: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/35.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 36: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/36.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 37: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/37.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 38: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/38.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 39: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/39.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 40: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/40.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 41: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/41.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 42: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/42.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 43: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/43.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 44: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/44.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 45: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/45.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 46: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/46.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 47: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/47.jpg)
Solving equationsSolving equations
Pseudo coding
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
Possible solution
2nd degree equation
Solve equation?
One equation*While answer n or N
Information
1
Constant a
3
Constant c
5
Constant b
4If D 0
Solution No real solution
11
2
2
One solution
If D 0
7 8
6
9 10
Two solutions
![Page 48: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/48.jpg)
Lego MindstormsLego Mindstorms
![Page 49: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/49.jpg)
Lego MindstormsLego Mindstorms
![Page 50: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/50.jpg)
Here’s an example of translating the pseudocode to C code
Solving equationsSolving equations
C
c:\windows\system\cool.dllProgram
![Page 51: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/51.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equations
int main(){ char answer;
I’m lost in cyberspace
![Page 52: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/52.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equations
int main(){ char answer;
I’m lost in cyberspace
![Page 53: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/53.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equations
int main(){ char answer;
I’m lost in cyberspace
![Page 54: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/54.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equations
int main(){ char answer;
![Page 55: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/55.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program information
int main(){ char answer; info();
Don’t worry!You’ll C!!
void info(void){ printf(”\nThis program will solve equations of the 2nd degree”); printf(”\n in the form of ax^2+bx+c=0.”); printf(”\nReturns only real values.”); printf(”\n”);}
![Page 56: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/56.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)
int main(){ char answer; info(); answer=ask_again();
Aha, this doesn´t seemto be that difficult!
char ask_again(void){ char c; printf(”\n Do you want to solve an equation? (y/n)”); while((c=getchar())==’\n’); return c;}
![Page 57: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/57.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)
int main(){ char answer; info(); answer=ask_again();
Make room! I’ve got more to say!
char ask_again(void){ char c; printf(”\n Do you want to solve an equation? (y/n)”); while((c=getchar())==’\n’); return c;}
![Page 58: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/58.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)
int main(){ char answer; info(); answer=ask_again();
Make room! I’ve got more to say!
char ask_again(void){ char c; printf(”\n Do you want to solve an equation? (y/n)”); while((c=getchar())==’\n’); return c;}
![Page 59: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/59.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N
int main(){ char answer; info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) {
Make room! I’ve got more to say!
![Page 60: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/60.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N
int main(){ char answer; info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) {
Make room! I’ve got more to say!
![Page 61: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/61.jpg)
Solving equationsSolving equations C coding
Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N
int main(){ char answer; info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) {
Make room! I’ve got more to say!
![Page 62: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/62.jpg)
Solving equationsSolving equations C coding
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
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, a, b, c);
![Page 63: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/63.jpg)
Solving equationsSolving equations C coding
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
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a;
![Page 64: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/64.jpg)
Solving equationsSolving equations C coding
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
else
end if else
end if
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a; if (D >= 0) { if (D == 0) {
} else {
} } else { }
If and else?I don’t get it!
![Page 65: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/65.jpg)
Solving equationsSolving equations C coding
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
else
end if else
end if
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a; if (D >= 0) { if (D == 0) {
} else {
} } else { }
If and else?I don’t get it!
Wait, check this out!
![Page 66: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/66.jpg)
Solving equationsSolving equations C coding
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
else
end if else
end if
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a; if (D >= 0) { if (D == 0) {
} else {
} } else { }
Voila!
calculate x = -b/(2a)display x
x = -b/(2*a);printf(”One solution X:%.2lf \n”, x);
![Page 67: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/67.jpg)
Solving equationsSolving equations C coding
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
end if else
end if
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a; if (D >= 0) { if (D == 0) { x = -b/(2*a); printf(”One solution X:%.2lf\n”, x); } else {
} } else { }
calculate x1= -b/(2a)+Dcalculate x2= -b/(2a)-Ddisplay x1, x2
x1 = -b/(2*a)+ sqrt(D);x2 = -b/(2*a)- sqrt(D);printf(”Two solutions X1:%.2lf X2:%.2lf\n”, x1, x2);
![Page 68: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/68.jpg)
Solving equationsSolving equations C coding
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
end if
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a; if (D >= 0) { if (D == 0) { x = -b/(2*a); printf(”One solution X:%.2lf\n”, x); } else { x1 = -b/(2*a)+ sqrt(D); x2 = -b/(2*a)- sqrt(D); printf(”Two solutions X1:%.2lf X2:%.2lf\n”, x1, x2); } } else { }
display No solution
printf(”No solutions!\n”);
![Page 69: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/69.jpg)
Solving equationsSolving equations C coding
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
int main(){ char answer;
info(); answer=ask_again(); while(answer != ’n’ && answer != ’N’) { printf(”Input a b c with spaces:”); scanf(”%lf%lf%lf”, &a, &b, &c); D = pow(b, 2)/(4*pow(a,2))-c/a; if (D >= 0) { if (D == 0) { x = -b/(2*a); printf(”One solution X:%.2lf\n”, x); } else { x1 = -b/(2*a)+ sqrt(D); x2 = -b/(2*a)- sqrt(D); printf(”Two solutions X1:%.2lf X2:%.2lf\n”, x1, x2); } } else { printf(”No solutions!\n”); } answer=ask_again(); }
c:\windows\system\cool.dllProgram
![Page 70: Examples Rules More examples Program structure Transfering the problem into code Split the problem into smaller problems Make a structure of the problems](https://reader035.vdocument.in/reader035/viewer/2022062802/56649ec05503460f94bcae82/html5/thumbnails/70.jpg)
THE END