0% found this document useful (0 votes)
4 views

Procedrual Programming Unit-1-5A.pptx

CS engineering

Uploaded by

parivnems
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Procedrual Programming Unit-1-5A.pptx

CS engineering

Uploaded by

parivnems
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

PCET’S Pimpri Chinchwad University, Pune

Course Name: Procedural Programming


Course Code: UBTFY114
Credit Units:03
Module-IA
Introduction to Computing
Prepared By: Pujitha Venna
Programming
Program
A well-defined set of instructions

Programming
Process of writing instructions in a language for a
computer to solve a specific task

Programming languages
Medium of communication between the man and the
machine

What language does the computer understand?


Categories of Programming Languages
Machine language
• Easily understood by the machine
• 0 and 1
• Tedious for programmers

Assembly Language
• Mnemonics (“add”, “sub”, etc.)

High Level Languages


• High Level Language Instructions (closer to English)
High Level Language - C Machine Language

Assembly Language
Tools Used to Develop a Computer
Program
• Compiler
• Interpreter
• Assembler
• Debugger
• Integrated Development Environment
Integrated Development Environment
One tool that integrates compiler/interpreter, debugger and
runtime environment in a user-friendly interface
Example: Netbeans
Execution of a C Program Using IDE
Clean and Build

Interacting with the program


Algorithm
• A sequence of computational steps that transform the
input into the output
•Set of finite steps that give the solution to a problem
•A procedure for solving a problem consists of
actions to be executed and
order in which these actions are to be executed
Characteristics of an Algorithm
•Input : If an algorithm says to take inputs, it should be
well-defined inputs. It may or may not take input.
•Output : The algorithm must clearly define what output will be
yielded and it should be well-defined as well. It should produce
at least 1 output.

•Precise: Each step should be clear and precise. No ambiguity


•Finiteness: An algorithm must terminate after a finite number
of steps.
•Effectiveness: An algorithm must be developed by using very
basic and simple operations. Every step in the algorithm must
be effective i.e. every step should do some work.
Advantages of Algorithm
•It is not dependent on any programming language, so it is
easy to understand.
•It is step-wise representation of a solution to a given
problem.
•It is a blueprint of a given problem solution.
•In an Algorithm the problem is broken down into smaller
pieces or steps hence, it is easier for the programmer to
convert it into an actual program.
Disadvantages of Algorithm
•Writing an algorithm takes a long time so it is
time-consuming.
•Understanding complex logic through algorithms can be
very difficult.
•Branching and Looping statements are difficult to show in
Algorithms
•Visual representation of program logic is not available in
algorithm.
Examples of Algorithm
Design an Algorithm To print a message
“Welcome to CSE”
Step 1: Start
Step 2: Display “Welcome to CSE”
Step 3: Stop
Design an Algorithm to add two numbers
Step 1: Start
Step 2: Accept inputs from user(Num1, Num2)
Step 3: calculate sum = Num1+Num2
Step 4: Display “sum”
Step 5: Stop
Examples of Algorithm

Design an Algorithm to find average of three


numbers
Step 1: Start
Step 2: Accept inputs from user(Num1, Num2, Num3)

Step 3: calculate Avg =( Num1+Num2+Num3)/3

Step 4: Display “Avg”


Step 5: Stop
Examples of Algorithm
Design an Algorithm to check the given year is leap
year or not
Step 1: Start
Step 2: Accept inputs from user (Year)
Step 3: If Year%4=0 goto Step 4 otherwise goto step 5
Step 4: Display “The given year is Leap Year” and

goto step 6

Step 5: Display “The given year is Non Leap Year”

Step 6: Stop
Examples of Algorithm
Design an Algorithm to find greatest among two
numbers.
Step 1: Start
Step 2: Accept inputs from user (Num1, Num2)
Step 3: If Num1>Num2 goto Step 4 otherwise goto step
5
Step 4: Display “Num1 is greatest among two numbers”

and goto step 6

Step 5: Display “Num2 is greatest among two numbers”

Step 6: Stop
Flowchart
• Flowchart is a visual representation of a process or an
algorithm.
• Step- by- Step approach to solve a task.
• A flowchart is a diagram that depicts the “flow” of a
program.
• Flowcharts are drawn using certain special-purpose
symbols such as rounded rectangle, parallelograms,
rectangles, diamonds, and small circles.
• Symbols are connected by arrows called flowlines
1
6
Advantages of Flowchart
•It helps to understand the flow of program control in an
easy way.
•Developing program code by referring its flow chart is
easier.
•It helps in avoiding semantic errors.
•Any concept is better understood with the help of visual
representation.
Flowchart Design Rules
•Standard symbols should be used while drawing flowchart.
•It must begin with a “Start” and (or BEGIN) and end with
STOP (or END).
•The standard process flow should be either from top to
bottom or from left to right.
•Flowchart should be neat, clean and easy to follow.
•Arrows should be aligned properly.
Flowchart Design Rules
•Only one flow line should come out from process symbol.
•Only one flow line should enter a decision symbol, but two
or three flow-lines, one for each possible answer, can leave
the decision symbol
•If the flowchart is lengthy and complex connector symbol
should be used to reduce the number of flow lines.
•Two arrows should not intersect or cross each other.
Basic Flowchart Symbols
• Terminators
– represented by rounded rectangles
– indicate a starting or ending of a problem.

Example:

STAR END
T
2
0
Basic Flowchart Symbols
• Input/Output Operations
– represented by parallelograms
– indicate an input or output operation

Example:

Read A, B Display
SUM
Basic Flowchart Symbols
• Processes
– represented by rectangles
– indicates a process such as a mathematical
computation or variable assignment

Example:

SUM=A+B.

2
2
Basic Flowchart Symbols

• Decision
– represented by diamond shape
– For decision making
– Contains an expression, such as a condition, that
can be either true or false

Example:
Is
a>b?
2
3
Decision Structure
• A new symbol, the diamond, indicates a yes/no question.
If the answer to the question is yes, the flow follows one
path. If the answer is no, the flow follows another path.

NO YES

24
Basic Flowchart Symbols
• Connectors
• represented by a small circle
• Sometimes a flowchart will not fit on one page.
• A connector allows to connect two flowchart
segments.
Example: A
START A

•The connector “A” indicates that the


second flowchart segment begins
where the first segment ends. END
A

25
Basic Flowchart Symbols
• Flow of data
– represented by an arrow.
– Always the flow should be from top to bottom or from
left to right.
– An arrow coming from one symbol and ending at
another symbol Represents that control passes to the symbol
the arrow points to.

Example:

26
Flowchart Examples
Draw a flowchart to add two numbers

Start

Read
Read a,a,b b

sum
sum =
= aa++
bb

Display “Sum of a and b


is ‘sum’ “

Stop
Flowchart Examples
Draw a flowchart to find average of two numbers

Start

Read
Read a,a,b b

avgsum
= (a= a++ b)/2
b

Display “Average of a
and b is ‘avg’ “

Stop
Flowchart Examples
Draw a flowchart to find area of circle.

Start

Read r

areasum
= 3.14*r*r
=a+b

Display “Area of a circle


is ‘area’ “

Stop
Review
• What do each of the following symbols
represent?

(Answer on next slide) 42


Answer
• What do each of the following symbols
represent?
Decision
Terminal

Input/Output
Operation Connector

Process Module

31
PseudoCode
• A Pseudo code is a step-By-step Representation of an algorithm
in code-like structure.
• It is an informal way of writing a program for better
understanding.
• It helps the programmer to understand logic of the program.
• It cannot be compiled nor executed.
• It uses reserved Keywords.
PseudoCode Rules
• One statement per line
• Initial keywords should capitalize.
• Indentation should be given similar as the statements are indented
in a computer program.
• Ending the statements and Looping is necessary.
• All statements should be simple and clear.
Basic Computer Operations to Write
Pseudo code Statements
1.A computer can receive information (Input)
READ (information from a file)
GET (information from the keyboard)
2. A computer can put out information (Output)
WRITE (information to a file)
DISPLAY (information to the screen)
Basic Computer Operations to Write
Pseudo code Statements
3. A computer can perform arithmetic
operations
Use actual mathematical symbols or the words for the symbols
Example: +, -, *, /
Add number to total
Total = total + number
▪ CALCULATE/ COMPUTE
Basic Computer Operations to Write
Pseudo code Statements
4. A computer can assign a value to a piece of data
i. To give data an initial value
INITIALIZE/ SET
ii. To assign a value as a result of some processing
“=”
iii. To keep a piece of information for later use
SAVE, STORE
iv. To declare a variable
DEFINE
Basic Computer Operations to Write
Pseudo code Statements
5. A computer can compare two piece of
information and select one of two alternative
actions
IF (condition) THEN
Some action
ELSE
Alternative action
ENDIF
Basic Computer Operations to Write
Pseudo code Statements
6. A computer can repeat a group of actions
i. While Loop
WHILE condition (is true)
Some action
ENDWHILE
ii. For Loop
FOR a number of times
Some action
ENDFOR
Advantages of pseudo code
1. It is easy to write pseudo code compared to code.
2. Easy to convert pseudo code to any computer
programming language.
3. It allows designer to focus on main logic.
4. It can be easily modified as compared to flowchart.
5. It can be read and understood easily.
Disadvantages of pseudo code
1. There are no standards keywords for writing pseudo codes.
2. Pseudo code cannot be compiled and executed so its
correctness cannot be verified by using computers.
3. In the case of pseudo code, a graphic representation of
program logic is not available.
4. Understanding complex logic through pseudo code can be
very difficult.
5. Branching and looping statements are difficult to show in
pseudo code.
Pseudocode Example
To add two numbers
BEGIN
DEFINE Integer Num1,Num2, Sum
READ Num1, Num2
CALCULATE Sum=Num1+Num2
DISPLAY “Sum of two numbers is ‘sum’”
END
Pseudocode Example
To find area and perimeter of a rectangle

BEGIN
DEFINE Integer length, breadth, area, perimeter
READ length, breadth
CALCULATE area= length *breadth
CALCULATE perimeter=2*(length+ breadth)
DISPLAY “Area of a rectangle is ‘area’ ”
DISPLAY “Perimeter of a rectangle is ‘perimeter’ ”
END
Pseudocode Example
To Check given number is even or odd
BEGIN
DEFINE Integer Num1
READ Num1
IF (Num%2=0) THEN
DISPLAY “The given number is even”
ELSE
DISPLAY “The given number is odd”
ENDIF
END
Practice Questions for Flowchart/
Pseudocode/Algorithm
•To print a message “Welcome to CSE”
•To calculate the sum and product of two numbers.
•To find an average of three numbers.
•Find Area Of Circle using Radius.
•To find the area and perimeter of a rectangle.
•To Calculate simple interest on principal P, rate R% and
duration T years.
Contd…
•To Convert temperature from Fahrenheit to Celsius.
•The voltage (V) between the poles of a conductor is equal to
the product of the current (I) passing through the conductor and
the resistance (R) present on the conductor. It’s demonstrated
by the V = I * R formula.

•To swap two numbers using third variable


•To swap without using third variable.
Contd…
•To determine if a person is eligible for a driving license or not
based on their age.
•To check the given number is even or odd.
•To check the given year is a leap year
•To Check a Number is Positive or Negative or Zero.
•To find the greatest among three numbers.

You might also like