Structured
Programming
Language
ALGORITHM, PSEUDO CODE, FLOW CHART,
COMPILATION PROCESS
Mohammad Imam Hossain
Lecturer, CSE, UIU
Algorithm
• Complete step by step representation of the solution of the
problem, represented in English like language.
Pseudo
Code
• More formal representation than the algorithm
• Very close to actual programming language
Flow chart
• Uses many graphical symbols to represent the steps of the
solution of the problem.
Program
• A set of instructions
• Written in a particular sequence in a computer-related language
Problem:Write a program to find the average of n numbers.
Algorithm:
1. Read the value of n
2. Read n numbers
3. Add these n numbers
4. Divide the addition
result by n to get the
average
5. Print the average
Pseudo Code:
1. Start
2. Read n
3. sum  0
4. for i  1 to n do
5. read i-th number
6. sum  sum + i-th number
7. end for
8. average  sum/n
9. print average
10. stop
Flow Chart
• Graphical Symbols
Start, Stop
Read, Print
Processing statements
Conditional check
Direction of flow
Connectors
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
sum=30+30=60, i=4
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
sum=30+30=60, i=4
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
sum=30+30=60, i=4
average=60/3=20
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
sum=30+30=60, i=4
average=60/3=20
yes
no
Problem:Write a program to find
the average of n numbers.
Flow Chart >>
start
Read n
sum  0
i  1
i<= n
?
Read numberi
sum  sum + numberi
ii+1
average  sum/n
Print average
stop
n=3 and the numbers are: 10,20,30
sum=0+10=10, i=2
sum=10+20=30, i=3
sum=30+30=60, i=4
average=60/3=20
yes
no
Practice problems:
1. Draw flow chart to decide whether a number is even or odd.
2. Draw flow chart to find out the sum of the following series:
a) 1+3+5+… … + 99
b) 1+
1
3
+
1
5
+ … … +
1
27
c) 1+1+2+3+5+8+13+… … + upto 100th terms (Fibonacci series)
3. Draw flow chart to find out the factorial of n,
1*2*3*… … *n
4. Draw flow chart to find out the maximum of 3 numbers.
5. Draw flow chart to check whether a number is prime or not.
6. Draw flow chart to find out the gcd of 2 numbers.
GCD Problem:
15 ) 21 ( 1
15
---------------
6 ) 15 ( 2
12
--------------
3 ) 6 ( 2
6
------------
0
GCD Problem:
15 ) 21 ( 1
15
---------------
6 ) 15 ( 2
12
--------------
3 ) 6 ( 2
6
------------
0
a b
check
GCD Problem:
15 ) 21 ( 1
15
---------------
6 ) 15 ( 2
12
--------------
3 ) 6 ( 2
6
------------
0
a b
check
GCD Problem:
15 ) 21 ( 1
15
---------------
6 ) 15 ( 2
12
--------------
3 ) 6 ( 2
6
------------
0
a b
check
GCD Problem:
15 ) 21 ( 1
15
---------------
6 ) 15 ( 2
12
--------------
3 ) 6 ( 2
6
------------
0
a b
check
Start
input a , b
check b % a
check=0
?
ba
a check
print a
stop
No
Yes
check b % a
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
C Preprocessor
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
PreprocessedCode
hello.i
C Preprocessor
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
PreprocessedCode
hello.i
C Preprocessor
C Compiler
2. Compilation is the second pass. It takes the
output of the preprocessor and the source
code and generates assembler source code.
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
PreprocessedCode
hello.i
Assembly code
hello.s
C Preprocessor
C Compiler
2. Compilation is the second pass. It takes the
output of the preprocessor and the source
code and generates assembler source code.
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
PreprocessedCode
hello.i
Assembly code
hello.s
C Preprocessor
C Compiler
Assembler
2. Compilation is the second pass. It takes the
output of the preprocessor and the source
code and generates assembler source code.
3. Assembly is the third stage that takes the
assembly source code and produces an assembly
listing with offsets.The assembler output is stored
in an object file.
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
PreprocessedCode
hello.i
Object code
hello.o
Assembly code
hello.s
C Preprocessor
C Compiler
Assembler
2. Compilation is the second pass. It takes the
output of the preprocessor and the source
code and generates assembler source code.
3. Assembly is the third stage that takes the
assembly source code and produces an assembly
listing with offsets.The assembler output is stored
in an object file.
C Programs Building Process:
C program building process involves four stages. At
the end there should be a single executable file.
1. Preprocessing is the first pass of any C
compilation. It processes include-files, define,
conditional compilation instructions and macros.
Source Code
hello.c
PreprocessedCode
hello.i
Executable code
hello.exe
Object code
hello.o
Assembly code
hello.s
C Preprocessor
C Compiler
Assembler
Linker
2. Compilation is the second pass. It takes the
output of the preprocessor and the source
code and generates assembler source code.
3. Assembly is the third stage that takes the
assembly source code and produces an assembly
listing with offsets.The assembler output is stored
in an object file.
4. Linking is the final stage that takes one or more
object files or libraries as input and combines them to
produce a single (executable) file.
Library Files
Other Object files
Relocation object
code information
Compiling using command prompt:
1. Write your code into a text editor and name the file with .c extention.
2. Add your gcc compiler’s bin directory path into windows environment
variables path variable.
3. Open windows command prompt and write the following command
gcc –c “path of your .c file with file name”
This command will generate the object file with .o extension let,
object_file_name.o
4.Then give the following command
gcc –o exe_file_name object_file_name.o