Structured thinking PowerPoint PPT Presentation

presentation player overlay
1 / 98
About This Presentation
Transcript and Presenter's Notes

Title: Structured thinking


1
Structured thinking
2
Contents
3
Structure diagram
Morningwhile has gold in mouthd
4
Sequence (order in time)
Sequence
Sequence parts
5
Structure diagram
Morningwhile has gold in mouthd
Division
Time
6
Selection
Selection
Selection parts
7
Structure diagram
Morningwhile has gold in mouthd
Division
Time
8
Iteration (repetition)
Iteration
As long as youre thirsty
Iteration part
9
Structure diagram
Morningwhile has gold in mouthd
Division
Time
10
Flow chart
11
Summary
  • A problem can be divided into a number of smaller
    problems.
  • When programming, it can sometimes be difficult
    to know where to start.This is where you use a
    structure diagram.

12
The endpart 1
13
Program structure
  • Examples
  • Rules
  • More examples

14
Crossing
Imagine driving in car B, just behind another car
A. You come to a crossing. How will you know
which direction it will chose?
Car A has to make a selection
B
15
Crossing a selection of directions
How can you see in which direction the car in
front of you will choose?
Crossing
16
Marriage - a selection?
not JSP
17
Selectionparts
  • A selection must contain at least two selection
    components. If It only contains one there is no
    selection.

Young mans future choice
18
Al Bundy?
It is however possible to leave a selection
component empty.
Young mans future choice

19
Example of an iteration
Label
20
Rules of Christmas
Santa Claus X-mas day
not JSP
21
Santa changed his mind
  • Parts connected to the same component must be of
    similar type

Santa Claus X-mas day
22
Paint house - an iteration
Paint
House
not JSP
23
Now you can begin to paint
  • An iteration can only contain one repeated
    component

Paint
House
24
Example of JSP
25
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

?
26
What is an operation?
  • An operation describes WHAT to do with all the
    data that exist in the structure.
  • An operation can for instance read information,
    calculate, sort, seek, print, etc..

27
Example Construct a programstructure to a
program that calculates and prints the area of a
circle
Operationlist - what do we need?
Program
We realize there is three important operations we
need to complete this task.
Radius and Area
  • First, we need to put in (input) the radius of
    the circle
  • Second, calculate the area
  • Third, print (output) the answer

28
And..
29
Operationlist
Operationlist
1. Read length of rectangle
2. Read width of rectangle
3. Read selection (area/circumference)
4. Calculate area of rectangle
5. Print area of rectangle
6. Calculate circumference
7. Print circumference of rectangle
Area or circumf.
Area
Cirumf.
A structure to a program that calculates the area
or the circumference to a rectangle
30
Program structure
Operationlist 1. Print headline of table 2. Input
value of x 3. Print x value 4. Calculate value if
y 5. Print y value Conditionlist (C 1) Until x
100
Program
Headline of
Table
table
Until x 100

Pair of
numbers
  • A conditionlist contains all the conditions used
    in the structure

31
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

32
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

33
Milk the cow - Pseudocode
Peasant needs
money
34
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
35
Milk the cow - Pseudocode
Peasant needs
money
IFneighbour_home yes
ELSE
By hand
WHILE milk exist

Squeeze
36
Milk the cow - Pseudocode
Peasant needs
money
Sell milk
If neighbour _home
37
Milk the cow - Pseudocode
Peasant needs
money
38
Pseudocode
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
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
39
Pseudocode
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
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
40
Pseudocode
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
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
41
Pseudocode
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
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
42
Pseudocode
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
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
43
Pseudocode
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
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
44
Pseudocode
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
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
45
Pseudocode
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
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
46
Pseudocode
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
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
47
Pseudocode
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
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
48
The endpart 2
49
Solving 2nd degree equations
  • Structure diagram
  • Structure diagram to pseudocode
  • Pseudocode to C programming

50
Solving 2nd degree equations
Program structure
D
51
Solving 2nd degree equations
Program structure
2nd degree equation
Information
52
Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N

One equation
53
Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N

One equation
Possible solution
Constant a
Constant c
Constant b
54
Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N

One equation
Possible solution
Constant a
Constant c
Constant b
If D ³ 0
Solution
No real solution
55
Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N

One equation
Possible solution
Constant a
Constant c
Constant b
If D ³ 0
If D 0
Two solutions
One solution
56
Solving 2nd degree equations
Program structure
2nd degree equation
Information
2
1
Possible solution
Constant a
Constant c
Constant b
2
6
If D ³ 0
5
4
3
If D 0
11
Two solutions
One solution
7
9
8
10
57
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
58
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
59
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
60
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
61
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
62
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
63
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
64
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
65
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
66
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
67
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
68
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
69
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
70
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
71
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
72
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
73
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
74
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
75
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
76
Lego Mindstorms
77
Lego Mindstorms
78
Solving equations
Heres an example of translating the pseudocode
to C code
Program
79
Solving equations
C coding
int main() char answer
Solving 2nd degree equations
Im lost in cyberspace
80
Solving equations
C coding
int main() char answer
Solving 2nd degree equations
Im lost in cyberspace
81
Solving equations
C coding
int main() char answer
Solving 2nd degree equations
Im lost in cyberspace
82
Solving equations
C coding
int main() char answer
Solving 2nd degree equations
83
Solving equations
C coding
int main() char answer info()
Solving 2nd degree equationsDisplay program
information
Dont worry! Youll C!!
84
Solving equations
C coding
int main() char answer info()
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)
Aha, this doesnt seem to be that difficult!
85
Solving equations
C coding
int main() char answer info()
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)
Make room! Ive got more to say!
86
Solving equations
C coding
int main() char answer info()
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)
Make room! Ive got more to say!
87
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Make room! Ive got more to say!
88
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Make room! Ive got more to say!
89
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Make room! Ive got more to say!
90
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
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
91
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a
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
92
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0)
else
else
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
93
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0)
else
else
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
94
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0)
else
else
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
x -b/(2a)printf(One solution X.2lf \n,
x)
calculate x -b/(2a)display x
95
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0) x
-b/(2a) printf(One solution
X.2lf\n, x) else
else
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
calculate x1 -b/(2a)ÖDcalculate x2
-b/(2a)-ÖDdisplay x1, x2
x1 -b/(2a) sqrt(D)x2 -b/(2a)-
sqrt(D)printf(Two solutions X1.2lf
X2.2lf\n, x1, x2)
96
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0) x
-b/(2a) printf(One solution
X.2lf\n, x) else
x1 -b/(2a) sqrt(D) x2 -b/(2a)-
sqrt(D) printf(Two solutions X1.2lf
X2.2lf\n, x1, x2)
else
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
display No solution
printf(No solutions!\n)
97
Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0) x
-b/(2a) printf(One solution
X.2lf\n, x) else
x1 -b/(2a) sqrt(D) x2 -b/(2a)-
sqrt(D) printf(Two solutions X1.2lf
X2.2lf\n, x1, x2)
else printf(No solutions!\n)
answerask_again()
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
Program
98
THE END
Write a Comment
User Comments (0)
About PowerShow.com