Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.

Commit b68a0db

Browse files
Readme
1 parent ece9d76 commit b68a0db

File tree

2 files changed

+108
-180
lines changed

2 files changed

+108
-180
lines changed

README.md

Lines changed: 108 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -314,53 +314,75 @@ The main goal of structured programming is to improve code readability, maintain
314314
# Chapter-09
315315
## Algorithms
316316

317-
According to the computer scientist Niklaus Wirth stated that- PROGRAM = ALGORITHMS + DATA
317+
* According to the computer scientist *Niklaus Wirth* stated that- **PROGRAM = ALGORITHMS + DATA**
318+
318319
An algorithm is a part of the plan for the computer program and an effective procedure for solving a problem in a finite number of steps. Algorithm may be represented in various ways. These are four ways of stating algorithms-
319-
• Step-form: The procedure of solving a problem is stated with written statements. Each statement solves a part of the problem and these together complete the solution. The step-form uses normal language to define each procedure.
320-
• Pseudo-code: The pseudo-code is a written form representation of the algorithm but it differs from the step-form as it uses a restricted vocabulary to define its action of solving the problem.
321-
• Flowchart & Nassi-Schneiderman: These two are graphically oriented representation forms. They use symbols and language to represent sequence, decision and repetition actions.
320+
321+
1. **Step-form:** The procedure of solving a problem is stated with written statements. Each statement solves a part of the problem and these together complete the solution. The step-form uses normal language to define each procedure.
322+
323+
2. **Pseudo-code:** The pseudo-code is a written form representation of the algorithm but it differs from the step-form as it uses a restricted vocabulary to define its action of solving the problem.
324+
325+
3. **Flowchart & Nassi-Schneiderman:** These two are graphically oriented representation forms. They use symbols and language to represent sequence, decision and repetition actions.
322326
Algorithms show these three features:
323-
1. Sequence (also known as process): Sequence means that each step or process in the algorithm is executed in the specific order.
324-
2. Decision (also known as selection): (if…. then, if…. then…. else…) In algorithms the outcome of a decision is either true or false; there is no state in between.
325-
If proposition
326-
then process1
327-
else process2
328-
This is the if… then… else… form of the decision. This means that if the preposition is true then execute process1, else, or otherwise, execute process2.
329-
3. Repetition (also known as iteration or looping): repeat and while. repeat loop, while loop, if… then go to ... loop. The repeat loop is used to iterate or repeat a process or sequence of processes until some condition becomes true. It has the general form:
330-
Syntax: Example:
331-
Repeat Repeat
332-
Process1 Fill water in kettle
333-
Process2 until kettle is full
334-
……….……
335-
ProcessN
336-
Until proposition
337-
338-
While preposition while kettle is not full
339-
Begin fill water in kettle
340-
Process1
341-
Process2
342-
……………
343-
ProcessN
344-
end
345-
346-
If … then goto … is:
347-
Process1 Fill some water in kettle
348-
Process2 if kettle not full then goto 1
349-
……………
350-
ProcessN
351-
If proposition then goto Process1
352-
353-
Constant and Variable: Constant is a fixed value that can’t be changed. On the other hand, the variable is a container for a value that may vary during the execution of the program. For example, in the tea-making algorithm, the cup and kettle are constant whether the water level, water temperature and quantity of tea leaves are variable.
327+
328+
1. **Sequence (also known as process):** Sequence means that each step or process in the algorithm is executed in the specific order.
329+
330+
2. **Decision (also known as selection):** (if…. then, if…. then…. else…) In algorithms the outcome of a decision is either true or false; there is no state in between.
331+
332+
If proposition
333+
then process1
334+
else process2
335+
336+
This is the if… then… else… form of the decision. This means that if the preposition is true then execute process1, else, or otherwise, execute process2.
337+
338+
3. **Repetition (also known as iteration or looping):** repeat and while. repeat loop, while loop, if… then go to ... loop. The repeat loop is used to iterate or repeat a process or sequence of processes until some condition becomes true. It has the general form:
339+
*Syntax:*
340+
341+
Process1 Fill water in kettle
342+
Process2 until kettle is full
343+
ProcessN
344+
Until proposition
345+
While preposition while kettle is not full
346+
347+
Begin
348+
fill water in kettle
349+
Process1
350+
Process2
351+
……………
352+
ProcessN
353+
end
354+
355+
If … then goto … is:
356+
Process1 Fill some water in kettle
357+
Process2 if kettle not full then goto 1
358+
……………
359+
ProcessN
360+
If proposition then goto Process1
361+
362+
**Constant and Variable:** Constant is a fixed value that can’t be changed. On the other hand, the variable is a container for a value that may vary during the execution of the program. For example, in the tea-making algorithm, the cup and kettle are constant whether the water level, water temperature and quantity of tea leaves are variable.
363+
354364
Developing algorithms using step-form:
365+
355366
1. START and STOP
356367
2. INPUT or READ
357368
3. PRINT
358369
4. Operators-
359-
a. Arithmetic Operators: ←; The expression X←6 means that a value 6 is assigned to the variable X. Examples: +, -, *, /, %
360-
b. Relational Operators
370+
a. Arithmetic Operators: ←; The expression X←6 means that a value 6 is assigned to the variable X. Examples: +, -, *, /, %
371+
b. Relational Operators
361372

362373
# Chapter-10
363374
## Algorithms and Flowcharts
375+
376+
### Algorithms
377+
In mathematics and computer science, an algorithm is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing calculations and data processing1.
378+
### Flowcharts
379+
380+
* A flowchart is a graph used to depict or show a step by step solution using symbols which represent tasks.
381+
* The symbols used consist of geometrical shapes that are connected by flow lines.
382+
* It is an alternative to using pseudocode; while a pseudocode description is verbal, a flowchart is graphical in nature.
383+
384+
**Symbols**
385+
<img src="https://www.researchgate.net/profile/Kenneth-Dekera/publication/338671462/figure/fig1/AS:848676255694848@1579351595020/Standard-Flowchart-Symbols.ppm">
364386
# Chapter-11
365387
## Pseudocodes
366388
* A pseudocode is a semiformal, (typically English) spoken-like language with limited vocabulary that can be used to design and describe algorithms.
@@ -428,7 +450,7 @@ b. Relational Operators
428450
loop-body
429451
end_while
430452

431-
<b><i>Example 5: Summing up 1 to 10</i></b>
453+
<b><i>Example 4: Summing up 1 to 10</i></b>
432454

433455
set cumulative sum to 0
434456
set current number to 1
@@ -439,146 +461,52 @@ b. Relational Operators
439461
print the value of cumulative sum
440462

441463
Pseudocode: The Repetition control structure
442-
• Subsequently, we can write the previous pseudocode
443-
(example 5) like this.
444-
• Example 6: Summing up 10 numbers
445-
cumulative sum = 0
446-
current number = 1
447-
while current number is less than or equal to 10
448-
cumulative sum = cumulative sum + current number
449-
current number = current number + 1
450-
end_while
451-
print the value of cumulative sum
452-
• Note that in this algorithm, we are using both the
453-
sequence and repetition control structure
454-
17
455-
Pseudocode: The Repetition control structure
456-
• Example 7:
457-
Begin
458-
number of users giving their birth date = 0
459-
while number of users giving their birth date < 10
460-
begin
461-
Read birth date from the user.
462-
Calculate the difference between the birth
463-
date and today’s date.
464-
Print the user’s age.
465-
if the age is greater than 55
466-
print “Pencen”
467-
else
468-
print “Kerja lagi”
469-
end_if
470-
number of users giving their birth date + 1
471-
end
472-
end_while
473-
End
474-
18
475-
Pseudocode: The Repetition control structure
476-
• Example 8:
477-
while user still wants to play
478-
begin
479-
Select either to play on a network or play against computer
480-
if play on network
481-
create connection to remote machine
482-
play game with connected computer
483-
else
484-
select mission
485-
play game locally
486-
end_if
487-
Ask user whether he/she still wants to play
488-
end
489-
end_while
490-
19
464+
465+
* Subsequently, we can write the previous pseudocode (example 5) like this.
466+
467+
<b><i>Example 5: Summing up 10 numbers</i></b>
468+
469+
cumulative sum = 0
470+
current number = 1
471+
while current number is less than or equal to 10
472+
cumulative sum = cumulative sum + current number
473+
current number = current number + 1
474+
end_while
475+
print the value of cumulative sum
476+
477+
*Note that in this algorithm, we are using both the sequence and repetition control structure*
478+
491479
Pseudocode: The Repetition control structure
492-
• Example 9:
493-
while user still wants to play
494-
begin
495-
Select either to play on network or play against computer
496-
if play on network
497-
create connection to remote machine
498-
play game with connected computer
499-
Else
500-
select mission
501-
play game locally
502-
end_if
503-
Ask user whether he/she still wants to play
504-
end
505-
end_while
506-
• For readability, always use proper indentation!!!
507-
20
508-
Flowcharts
509-
• A flowchart is a graph used to depict or show
510-
a step by step solution using symbols which
511-
represent tasks.
512-
• The symbols used consist of geometrical
513-
shapes that are connected by flow lines.
514-
• It is an alternative to using pseudocode; while
515-
a pseudocode description is verbal, a
516-
flowchart is graphical in nature.
517-
21
518-
Flowchart Symbols
519-
Terminal symbol - indicates the beginning and
520-
end points of an algorithm.
521-
Process symbol - shows an instruction other than
522-
input, output or selection.
523-
Input-output symbol - shows an input or an output
524-
operation.
525-
Disk storage I/O symbol - indicates input from
526-
or output to disk storage.
527-
Printer output symbol - shows hardcopy printer
528-
output.
529-
22
530-
Flowchart Symbols cont…
531-
Selection symbol - shows a selection process
532-
for two-way selection.
533-
Off-page connector - provides continuation
534-
of a logical path on another page.
535-
On-page connector - provides continuation
536-
of logical path at another point in the same
537-
page.
538-
Flow lines - indicate the logical sequence of
539-
execution steps in the algorithm.
540-
23
541-
Flowchart – sequence control structure
542-
Statement 2
543-
Statement 1
544-
Statement 3
545-
:
546-
24
547-
Flowchart – selection control structure
548-
Condition
549-
elsestatement(s)
550-
thenstatement(s)
551-
No Yes
552-
25
553-
Flowchart – repetition control structure
554-
Condition Loop
555-
Statement(s)
556-
yes
557-
no
558-
26
559-
Flowchart – example 1
560-
Begin
561-
Read birth date
562-
Calculate
563-
Age = current year – birth date
564-
Display age
565-
End
566-
27
567-
Flowchart – example 2
568-
Begin
569-
Read age
570-
End
571-
YES Age > 55? NO
572-
print “Pencen” print “Kerja lagi”
573-
28
574-
Flowchart – example 5
575-
Begin
576-
End
577-
current_number <= 10?
578-
NO
579-
YES
580-
sum = 0
581-
current_number = 1
582-
sum = sum + current_number
583-
current_number = current_number + 1
584-
print sum
480+
481+
<b><i>Example 6:</i></b>
482+
483+
begin
484+
Read birth date from the user.
485+
Calculate the difference between the birth
486+
date and today’s date.
487+
Print the user’s age.
488+
if the age is greater than 55
489+
print “Pencen”
490+
else
491+
print “Kerja lagi”
492+
end_if
493+
number of users giving their birth date + 1
494+
end
495+
end_while
496+
End
497+
498+
<b><i>Example 7: while user still wants to play</i></b>
499+
500+
begin
501+
Select either to play on a network or play against computer
502+
if play on network
503+
create connection to remote machine
504+
play game with connected computer
505+
else
506+
select mission
507+
play game locally
508+
end_if
509+
Ask user whether he/she still wants to play
510+
end
511+
end_while
512+

media_files/flowchart.ppm

19.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)