Programming Concept
• Problem analysis
• Algorithm build-up
• Flowcharts and Pseudo-coding
• Programming language
Data types
Expressions
Control flow
CSE 101
1
Algorithm
• A procedure to perform a particular task.
• A set of finite rules or instructions to solve a particular problem.
• Algorithm design is language-independent
• Algorithms are commonly written in natural language, pseudocode
and flowcharts.
• Widely used in mathematics, engineering, commerce, IT, and
computer programming.
• Very useful for solving complex problems efficiently and effectively.
CSE 101
2
Algorithm
CSE 101
3
Algorithm
• Example: Write an algorithm to add two numbers.
Algorithm: Addition of two numbers
Step 1: Get two numbers as input.
Step 2: Add those two numbers.
Step 3: Write/Show the result.
Step 4: End.
• Example: Write an algorithm to find the bigger between two numbers.
Algorithm: To find the larger number
Step 1: Input two numbers.
Step 2: Check if the first number is bigger than the second then
Display the first number as the bigger number.
Step 3: Else/Otherwise display the second number as the bigger number.
Step 4: End.
CSE 101
4
Pseudocode
• Pseudocode is an algorithm that is a combination of natural language
and conventions of programming languages (like assignment operator,
conditional operator, loop) with informal notations.
• Example: Write a pseudocode to add two numbers.
Algorithm: Addition(a,b,c)
This pseudocode adds two numbers.
• Step 1: Get two numbers in a and b as input.
• Step 2: Add those two numbers; c=a+b.
• Step 3: Write/Show the result stored in c.
• Step 4: End.
CSE 101
5
Pseudocode
• Example: Write an algorithm to find the bigger between two numbers.
Algorithm: Larger number (a,b)
Step 1: Input two numbers a and b.
Step 2: Check if a>b
Display a as the bigger number.
Step 3: Else/Otherwise display b as the bigger number.
Step 4: End.
CSE 101
6
Flowchart
• A flowchart is a graphical or pictorial presentation of a process or system.
• Here, several geometric patterns are used to illustrate the numerous actions the
process or system carries out.
• Basic symbol:
CSE 101
7
Flowchart
• Example: Draw a flowchart to find the bigger between two numbers.
Begin
Input two numbers
True
If the
1st number > the
False
2nd number
Display the 2nd
number
Display the 1st
number
End
CSE 101
8
Programming Language
• A programming language is a language used to write computer
programs.
• The source code for a computer program is written using a
programming language.
• It is used to implement an algorithm.
• Different categories:
Machine language (0,1).
Assembly language (alphanumeric codes as instructions: ADD A,B,C, MOV
R, 35H )
High level language
CSE 101
9
High Level Language
• A programming language that is closer to natural language. It is easy
to write and understand.
• More readable, maintainable, and portable.
• Allows programmers/developers to focus on solving problems rather
than dealing with low-level details of the computer system/hardware.
CSE 101
10
High Level Language
Based on application area:
• Commercial language (business related problems; COBOL)
• Scientific language (scientific mathematical problem; FORTRAN)
• Special purpose language (Database; SQL)
• General purpose language (different software application; C, C++, JAVA,
Python)
CSE 101
11
High Level Language
Based on design paradigm:
• Procedure oriented language (sequence of procedures, performs a specific
task, calls one another; FORTRAN, C, BASIC)
• Logic oriented language (uses predicate logic to define relationship between
rules and facts; PROLOG)
• Object Oriented Programming (OOP) (Objects)
CSE 101
12
Structured Programming Language
• A programming approach that supports the following major features:
• Block structure: A problem/program is subdivided into small modules or blocks so that the
program becomes easy to develop and understand.
• Subroutine: A block of code that performs a specific task and can be reused throughout the
program.
• Control flow: The order of execution.
• Repetition: Execution of same set of instructions several times.
• It is easier to understand, maintain and debug.
• Reusable.
• User friendly.
• Machine independent.
• Also called Modular programming.
CSE 101
13
Data Types
Information of a student:
• Name: Ameena (String)
• Age: 20 (Whole number, Integer)
• Sex: F (Character)
• ID: CSE2001 (Alphanumeric)
• Marks: 89.5 (Floating point number)
CSE 101
14
Expressions
• A combination of operators, and operands (variables and constants).
• Example: average=(number1+number2)/2
• Types
Constant expression
Integral expression
Floating expression
Relational expression
Bitwise expression
Pointer expression
Logical expression
CSE 101
15
Control Flow
• The order in which instructions/statements/functions are executed
when a program is running.
• Example:
If marks >= 40
result ← pass
Else
result ← fail
CSE 101
16
Control Flow (contd.)
Sequence (do this and then this and then this . . . )
Example: x=10
y=x+10
y=y+10
Selection (if, else, switch, case)
Example: If marks >= 40 and <49
result ← D
Else if marks >= 50 and <59
result ← C
Else
result ← F
CSE 101
17
Control Flow (contd.)
Iteration (repeat, until, for, while)
Example: while (true)
do this
Procedure/subroutine call
Example: int addition(int a,int b);
int calculator(int result);
int calculator(int result){
....
addition (4,5)
....
}
CSE 101
18
Control Flow (contd.)
Recursion: A recursive procedure/subroutine calls itself.
Example: factorial of 5
Fact5=5*fact of 4
=5*(4*(fact of 3))
=5*(4*(3*(fact of 2)))
=5*(4*(3*(2*(fact of 1))))
=5*(4*(3*(2*(1*(fact of 0)))))
=5 *(4*(3*(2*(1*1))))
=5 *(4*(3*(2*1)))
=5 *(4*(3*2))
=5 *(4*6)
=5*24
=120
• Concurrency : multiple actions are performed simultaneously.
CSE 101
19
C
• General purpose language.
• Structured & Procedural programming language.
• Mid level language.
• Designed by Dennis Ritchie in 1972, Bell laboratory, to implement
UNIX OS.
• In 1989, American National Standards Institute (ANSI) approved a
standard edition of C; ANSI C.
CSE 101
20
Steps to Execute a C program
Step 1: Write/Create the source code (program) in an editor.
Step 2: Save the program with .c extension.
Step 3: Compile the program.
Step 4: Link the program.
Step 5: Execute/Run the program.
CSE 101
21
Execution Process of a C Program
*Figure collected from the Internet
CSE 101
22