Friday, August 21, 2015

8. Computer Programming with flowcharting Technique (page 8)



Example problem 4
You are asked to makes program to present the biggest number from INPUT three level unequal numbers.

Solution
For example the number K, L and M
Firstly compares K with L. There are two possibilities.

First possibility:
If K > L hence continuing compares K with M.
If simply of course K > M means K the biggest number since have already won K at the next and first step wins M also.
If no (M larger ones) hence M is the biggest number since have already won K which has give L. In this case no more require M compares with L.

Second possibility
If no (K < L) hence comparing L with M
If simply L > M hence L is the biggest number because winning K and M.
If no (M > L) hence M is the biggest number because has won L larger ones from K

Description:
The problem of this is beginning of from logic which must be mastered truly.

Program Listing
10 CLS
15 PRINT “PROG04A”
20 INPUT K
30 INPUT L
40 INPUT M
50 IF K > L THEN 90
60 IF L > M THEN 120
70 PRINT M
80 END
90 IF K > M THEN 110
100 PRINT M
105 GOTO 80
110 PRINT K
115 GOTO 80
120 PRINT L
125 GOTO 80

Description
1. At Flowchart 4 A. After statement PRINT must be figured in GOTO
Except line number 70
(May also be added 75 GOTO 80 although unnecessary)
Command (statement) this GOTO often is forgotten. As a result there will be mistake at the time of in RUN
2. If paid attention simply there is two PRINT M.
Its logic is of course that way. Please compare to flowchart 4 B and 4 C.
At flowchart 4 B and 4 C obtained to be each two PRINT K, L, and M
Flowchart 4 A, 4 B and 4 C when in RUN will yield output which are same.
3. Writing of line number can be done like at flowchart 4 B or 4 C
4. Choice Y (Yes) and N (NO) at Decision Symbol towards right can and downward or on the contrary. Under this example of if Y (Yes) downward and N(NO) towards right.
5. Hereinafter is all content of this book Y (Yes) in right and N (NO) direction downward Decision Symbol. This for uniformity and amenity only

DATA TEST:
Firstly: INPUT K is filled by number 1, INPUT L Number 2, INPUT M number 3
Second: INPUT K is filled by number 1, INPUT L Number 3, INPUT M number 2
Third: INPUT K is filled by number 2, INPUT L Number 1, INPUT M number 3
Fourth: INPUT K is filled by number 2, INPUT L Number 3, INPUT M number 1
Fifth: INPUT K is filled by number 3, INPUT L Number 1, INPUT M number 2
Sixth: INPUT K is filled [by] number 3, INPUT L Number 2, INPUT M number 1
OUTPUT is number 3 (the biggest number out of the three data)
Hereinafter your input can have kinds of number.

Followers

Blog Archive