You are on page 1of 65

Fundamentals of Programming (FOP)

(CE3002)

Unit – 1
Introduction to Computer
Programming
(Part – 1)
Mr. Viral H. Panchal
Computer Engineering Department
CGPIT, UTU
Topics to be covered
 Looping

➢ Understanding Computer Systems and Computer Languages


➢ Programming Paradigm and Classification
✓ Types of Programming Paradigms
▪ Imperative Programming Paradigms
▪ Declarative Programming paradigms
➢ Programming Development Process
➢ Pseudocode Statements and Flowchart
✓ Algorithm
✓ Flowchart
✓ Programming Constructs / Programming Structures
✓ Algorithm and Flowchart Examples
Understanding Computer Systems and Computer Languages
 Computer system is a combination of all the components required to process and store data
using computer. Every computer system is composed of multiple pieces of hardware and
software.
 Hardware is the equipment, or the physical devices, associated with a computer. For example,
keyboards, mice, speakers, and printers are all hardware.
 Software is computer instructions that tell the hardware what to do. Software is programs -
instructions written by programmers.
 Software can be classified as application software or system software.
 Application software comprises all the programs you apply to a task - word-processing
programs, spreadsheets, payroll and inventory programs, and even games.
 System software comprises the programs that you use to manage your computer,
including operating systems such as Windows, Linux, or UNIX.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 4
Operations of Computer Systems
 Together, computer hardware and software accomplish three major operations in most
programs: input, processing, and output.
 Input – Data items enter the computer system and are put into memory, where they can be
processed.
 Hardware devices that perform input operations include keyboards and mice.
 Data items include all the text, numbers, and other information that are processed by a
computer.
 Processing – Processing data items may involve organizing or sorting them, checking them for
accuracy, or performing calculations with them.
 The hardware component that performs these types of tasks is the central processing
unit, or CPU.
 Output – After data items have been processed, the resulting information usually is sent to a
printer, monitor, or some other output device so people can view, interpret, and use the results.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 5


Operations of Computer Systems
 Storage - Some people consider storage as a fourth major computer operation.
 Instead of sending output to a device such as a printer, monitor, or speaker where a
person can interpret it, you sometimes store output on storage devices, such as a disk
or flash media.
 People cannot read data directly from these storage devices, but the devices hold
information for later retrieval.
 When you send output to a storage device, sometimes it is used later as input for
another program.
 You write computer instructions in a computer programming language, such as Visual
Basic, C#, C++, or Java. Just as some people speak English and others speak Japanese,
programmers also write programs in different languages.
 The instructions you write using a programming language are called program code; when
you write instructions, you are coding the program.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 6
Operations of Computer Systems
 When you write a program, you usually type its instructions using a keyboard.
 When you type program instructions, they are stored in computer memory, which is a
computer’s temporary, internal storage.
 Internal storage is volatile - its contents are lost when the computer is turned off or loses
power.
 Usually, you want to be able to retrieve and perhaps modify the stored instructions later, so
you also store them on a permanent storage device, such as a disk.
 Permanent storage devices are non-volatile - that is, their contents are persistent and are
retained even when power is lost.
 Random access memory, or RAM, is a form of internal, volatile memory. It is hardware on
which the programs that are currently running and the data items that are currently being
used are stored for quick access.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 7


Operations of Computer Systems
 After a computer program is stored in memory, it must be translated from your programming
language statements to machine language that represents the millions of on/off circuits within
the computer.
 Each programming language uses a piece of software, called a compiler or an interpreter, to
translate your program code into machine language.
 Machine language is also called binary language, and is represented as a series of 0s and
1s.
 The program statements you write in a programming language are known as source code. The
translated machine language statements are known as object code.
 Only after program instructions are successfully translated to machine code the computer can
carry out the program instructions.
 When instructions are carried out, a program runs, or executes.
 In a typical program, some input will be accepted, some processing will occur, and results
will be output.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 8
Programming Paradigm and Classification
 The programming paradigm is defined as a set of principles, ideas, design
concepts and norms that defines the manner in which the program code is written
and organized.
 The programming paradigm does not specify the programming language syntax.
 The paradigm simply defines the program structure and the set of principles that
the programming language compiler should enforce.
 A programming paradigm is a framework that defines how the programmer can
conceptualize and model complex problem to be solved.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 10


Types of Programming Paradigms

Figure: Types of programming paradigm

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 11


Imperative Programming Paradigms
 The imperative paradigm is said to be command driven.
 The program code directs the program execution as sequence of statements executed one
by one.
 It consists of set of program statements. Each statement directs the computer to perform
specific task.
 The programmer has to elaborate each statement in details. Each statement directs what is
to be done and how it is to be done.
 The execution of the program statements is decided by the control flow statements. And
the program flow can be directed as per the program logic.
 The imperative paradigm programming languages include C, Fortran, Algol, Pascal and
Basic.
 Imperative programming is divided into three broad categories: Procedural, OOP and
parallel processing.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 12
Procedural programming paradigm
 The program based on procedural paradigm consist of set of procedures.
 The procedures are also referred as function, method or subroutines.
 The program structure in procedural programming consists of set of functions. Each
performs a specific operation.
 The function consists of group of computational steps that directs the computer to
perform specific operation.
 The function once defined can be called many times in the program to repeat the same
operation.
 The programmer can either use standard library functions or create library of user
defined functions.
 The examples of procedural programming languages are C, C++, Java, Pascal, etc.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 13


Object-oriented programming
 In object-oriented programming, all the program components are represented as
objects.
 An object binds the data and associated methods together as single unit.
 As such the programmer can control the data access permissions by defining the
access specifier.
 The object-oriented programming protects the program data from inadvertent
operations by another methods. And therefore, the object-oriented programming
offers robust security features.
 The examples of object-oriented programming languages are C++, Java, Python,
VB.Net, etc.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 14


Parallel processing approach
 Parallel processing is the processing of program instructions by dividing them
among multiple processors.
 A parallel processing system have many numbers of processor with the objective
of running a program in less time by dividing them.
 This approach seems to be like divide and conquer.
 Examples are NESL (one of the oldest one) and C/C++ also supports because of
some library function.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 15


Declarative Programming Paradigms
 The declarative paradigm is a programming paradigm that is focused on the logic of the
program and the end result.
 In this paradigm the control flow is not the important element of the program.
 The main focus of the declarative style of programming is achieving the end result.
 This paradigm is straight forward and to the point while writing the program code.
 The declarative approach to the programming is pretty much straight forward that leads
to what is to be done.
 On the contrary, the imperative style of programming consists of number of
computational statements that focuses on how it is to be done.
 Declarative programming is divided into three broad categories: Logic, Functional and
Database programming.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 16


Logic programming paradigm
 The logic programming is a declarative programming paradigm that is based on the logic
and the control.
 The term logic essentially means facts and rules, whereas the control means an order of
rules.
 The term algorithm is defined as logic plus control. The logic defines what should be solved
whereas the control defines how it should be solved.
 The main advantage of the logic programming is that the programmer needs to simply
define the what part of the problem. And the system finds the best solution to that problem.
 The logic programming is an abstract model of computation. It is based on the first order
predicate logic. The predicate logic is also referred to as first order logic.
 The clauses are an important element of the logic programming. In other words, a logic
program is a set of clauses.
 The Prolog is an example of declarative paradigm rule-based logic programming language.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 17
Functional programming paradigm
 The functional programming paradigms has its roots in mathematics and it is
language independent.
 The key principle of this paradigms is the execution of series of mathematical
functions.
 The central model for the abstraction is the function which are meant for some
specific computation and not the data structure.
 Data are loosely coupled to functions. The function hides their implementation.
 Function can be replaced with their values without changing the meaning of the
program.
 Some of the languages like perl, javascript mostly uses this paradigm.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 18


Database/Data driven programming approach
 This programming methodology is based on data and its movement.
 Program statements are defined by data rather than hard-coding a series of steps.
 A database program is the heart of a business information system and provides
file creation, data entry, update, query and reporting functions.
 There are several programming languages that are developed mostly for database
application.
 For example, SQL. It is applied to streams of structured data, for filtering,
transforming, aggregating (such as computing statistics), or calling other
programs. So, it has its own wide application.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 19


Programming Development Process
 Programming is a process of problem solving. To be a good problem solver and a good
programmer, you must follow good problem-solving techniques.
 In Programming Development Process, the programming steps or problem-solving process
requires the following steps. This is also referred to as the Programming Development Cycle.
 Problem analysis - Understand the problem.
 Logic formulation or plan the logic - Design the algorithm.
 Code the program - Write the Source Program using a Programming Language
 Compile and link the source program to produce the executable program - Use a compiler or
interpreter to translate the program into machine language.
 Test the executable program - confirm your program’s correctness by testing the executable
program several times using a variety of data.
 Use the Executable program - Put the program into production.
 Maintain the program - Make changes or revisions for new requirements in the program's
input/process/output.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 21
Programming Development Process

Figure: Program development cycle


Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 22
Problem analysis
 Analyzing the problem is the first and most crucial step in programming.
 This step requires you to do the following:
 Completely understand the problem.
Understand all the problem requirements with regards to its INPUT, OUTPUT
and PROCESS operations.
 If the problem is complex, divide the problem into sub-problems, analyze each
sub-problem, and understand each sub-problem’s requirements.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 23


Logic formulation or plan the logic
 During this phase, the programmer plans the steps of the program, deciding what steps to
include and how to order them. This is known as the algorithm.
 You can plan the solution to a problem in many ways. The two most common planning tools are
flowcharts and pseudocode.
 If the problem is complex, you broke the problem into subproblems, you need to design an
algorithm for each subproblem.
 Once you design an algorithm, you need to check it for correctness.
 Planning the logic includes thinking carefully about all the possible data values a program
might encounter and how you want the program to handle each scenario.
 The process of walking through a program’s logic on paper before you actually write the
program is called desk-checking.
 The programmer shouldn’t worry about the language syntax during this stage, but should rather
focus on figuring out what sequence of events will lead from the available input to the desired
output.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 24
Code the program
 Once you have designed the algorithm and verified its correctness, the next step
is to convert it into an equivalent programming code by coding the program in one
of more than hundreds of programming languages.
 You then use a text editor to enter the programming code or the program into a
computer.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 25


Compile and link the source program to produce the executable program
 Next, you must make sure that the program follows the language’s syntax. To verify the
correctness of the syntax, you run the code through a compiler.
 A computer program must be free of syntax errors before you can execute it.
 Usually, the software displays a list of syntax errors, which the programmer corrects. If the
compiler generates error messages, you must identify the errors in the code, correct them,
and then run the code through the compiler again.
 When all the syntax errors are removed, the compiler generates the equivalent machine
code, the linker links the machine code with the system’s resources, and the loader places
the program into main memory so that it can be executed.
 Usually when writing a program, a programmer might need to re-compile the code several
times.
 An executable program is created only when the code is free of syntax errors.
 When you run an executable program, it typically also might require input data.
Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 26
Compile and link the source program to produce the executable program

Figure: Creating an executable program


Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 27
Test the executable program
 The final step is to execute the program and test with some data to verify for
correct outputs.
 The compiler guarantees only that the program follows the language’s syntax. It
does not guarantee that the program will run correctly.
 A program that is free of syntax errors is not necessarily free of logical errors.
 During execution, the program might terminate abnormally due to logical errors,
such as division by zero or may not even terminate due to an endless loop.
 Even if the program terminates normally, it may still generate erroneous results.
 Under these circumstances, you may have to re-examine the code, the
algorithm, or even the problem analysis.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 28


Use the executable program
 Once the program is tested adequately, it is ready for an individual or organization
to use it.
 Putting the program into production might mean simply running the program only
once, if it was written to satisfy a user’s request for a special list.
 However, the process might take longer if the program will be run on a regular
basis, or if it is one of a large system of programs being developed.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 29


Maintain the program
 After programs are put into production, making necessary changes is called
maintenance.
 These changes or revisions maybe for new requirements in the Program's
Input/Process/Output.
 Like new format or specification for input or output data or requiring a new
revision or additional operating process or computation.
 When you make changes to existing programs, you repeat the development cycle.
 That is, you must understand these changes, plan, code, translate, and test
them again before putting them into production.
 If a substantial number of program changes are required, the original program
might be retired, and the program development cycle started for a new program.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 30


Pseudocode Statements and Flowchart
 When programmers plan the logic for a solution to a programming problem, they
often use one of two tools: pseudocode (pronounced “sue-doe-code”) or
flowcharts.
 Pseudocode is an English-like representation of the logical steps it takes to solve
a problem.
 A flowchart is a pictorial representation of the same thing.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 32


Algorithm
 An algorithm is defined as sequence of steps to solve a problem (task).
The steps must be finite, well defined and unambiguous.
 Writing algorithm requires some thinking.
 Algorithm can also be defined as a plan to solve a problem and represents its
logic.
 Note that an algorithm is of no use if it does not help us arrive at the desired
solution.
 For accomplishing a particular task, different algorithms can be written.
 Different algorithms can differ in their requirements of time and space.
Programmer selects the best suited algorithm for the given task to be solved.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 33


Characteristics of algorithm
1. It should have finite number of steps.
2. The steps must be in order and simple.
3. Each step should be defined clearly stated i.e., without ambiguity.
4. Must include all required information.
5. Should exhibit at least one output.

 Different algorithms have different performance characteristics to solve the same


problem.
 Some algorithms are fast. Some are slow. Some occupy more memory space. Some
occupy less memory space. Some are complex and some algorithms are simple.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 34


Flowchart
 A flowchart is a pictorial (graphical) representation of an algorithm.
 A flowchart is drawn using different kinds of symbols.
 A symbol is used for a specific purpose. Each symbol has name.
 Flowcharts use different shapes of boxes to denote different type of instructions.
 ANSI recommended a number of different rules and guidelines to help standardize the
flowcharting process.
 Flowchart helps to divide a large complex problem into small manageable ones.
 Generally, algorithm is first represented as a flowchart and then expressed in a
programming language.
 While preparing a flowchart, the sequence, selection and iterative structures may be
used wherever required.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 35


Rules for drawing flowchart
1. It should contain only one start and one end symbol.
2. The relevant symbols must be used while drawing a flowchart.
3. The direction of arrows should be top to bottom and left to right.
4. It should be simple and drawn clearly and neatly.
5. Be consistent in using names, variables in the flowchart.
6. Use properly labelled connectors to link the portions of the flowchart on
different pages.
7. The branches of decision box must be label.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 36


Flowchart symbols
Symbol Symbol Name Description

Used to start flowchart as well as to terminate


Start and Stop
flowchart.
Input / Output Used for input and output operation.
Process or expression
Used to represent any assignment or expression.
representation
Decision Used for any decision-making statement.
Direction of data flow
These arrows indicate the flow of sequence.
or flow lines
Connector Used for connecting flow lines from different places.

Loop Used for iteration or looping statement.


Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 37
Advantages and disadvantages of flowchart
 Advantages -
1. Conveys better meaning.
2. Analyses the problem effectively.
3. Good tool for documentation.
4. Provide guide for coding.
5. Systematic debugging.
6. Systematic testing.
 Disadvantages -
1. Takes more time to draw.
2. Difficult to make changes.
3. Non-standardization - No standards to determine how much details should
be included in a flowchart.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 38


Programming Constructs / Programming Structures
 There are three basic programming constructs or programming structures.
1. Sequence
2. election
3. Iteration (Loop)

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 39


Sequence
 Sequence logic is used for performing instructions
one after another in sequence.
 Sequence is the most basic of the constructs.
 It is simply performing one step after another.
 Each step is followed in a specific sequence, hence
the name.
 Sequence can be thought of as “do this, then do
this, then do this”.

Figure: Sequence structure

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 40


Selection
 Selection logic, also known as decision logic, is
used for making decisions.
 Selection logic is depicted as either an
if…then…else or if…then structure.
 Selection is the decision-making construct.
 It is used to make yes/no or true/false
decisions logically.
 Selection can be thought of as “if something is Figure: Selection structure
true, take this action, otherwise take that
action”.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 41


Iteration (Loop)
 Iteration logic is also known as loop.
 Iteration logic is used when one or more
instructions may be executed several times
depending on some condition.
 Iteration comes from the word “reiterate”, which
means to repeat.
 Iteration is a looping construct.
 Iteration is a combination of decision and Figure: Iteration (loop) structure
sequence and can repeat steps.
 Iteration can be thought of as “while something
is true, do this, otherwise stop”.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 42


Algorithm and Flowchart Examples
 To find sum of two numbers.
Algorithm: Flowchart:
1. Start
2. Read A,B
3. C=A+B
4. Print or display C
5. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 43


Algorithm and Flowchart Examples
 To Find area of the square.
Algorithm: Flowchart:
1. Start
2. Read length, L
3. Area = L*L
4. Print or display Area
5. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 44


Algorithm and Flowchart Examples
 To Find area of the rectangle.
Algorithm: Flowchart:
1. Start
2. Read side length, A
3. Read side length B
4. Area = A*B
5. Print or display Area
6. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 45


Algorithm and Flowchart Examples
 Interchange the value of two numbers.
Algorithm: Flowchart:
1. Start
2. Read two values into two variables A, B
3. Declare third variable, C
4. C=A
5. A=B
6. B=C
7. Print or display A, B
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 46


Algorithm and Flowchart Examples
 Calculate the average for three numbers.
Algorithm: Flowchart:
1. Start
2. Read 3 numbers A, B, C
3. Calculate the average by the equation
Average = (A + B + C)/3
4. Print Average
5. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 47


Algorithm and Flowchart Examples
 Find the largest of two numbers.
Algorithm: Flowchart:
1. Start
2. Read A,B
3. If A>B then
Print A is large
else
Print B is large
4. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 48


Algorithm and Flowchart Examples
 Find the sum of first five natural numbers.
Algorithm: Flowchart:
1. Start
2. Read n
3. Initialize count = 0, sum = 0
4. count = count + 1
5. sum = sum + count
6. Repeat steps 4 and 5 until count>5
7. Print sum
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 49


Algorithm and Flowchart Examples
 Calculate simple interest using the expression (SI=PNR/100).
Algorithm: Flowchart:
1. Start
2. Read P, N, R
3. SI=(P*N*R)/100
4. Print SI
5. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 50


Algorithm and Flowchart Examples
 Convert temperature from Fahrenheit to Celsius.
Algorithm: Flowchart:
1. Start
2. Initialize F = 0, C = 0
3. Read F
4. C = (F-32) * 5/9
5. Write C
6. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 51


Algorithm and Flowchart Examples
 Calculate sum of integers 1 to 100.
Algorithm: Flowchart:
1. Start
2. Initialize count i = 1, sum = 0
3. sum = sum + i
4. Increment i by 1
5. Repeat steps 3 and 4 until i > 100
6. Print sum
7. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 52


Algorithm and Flowchart Examples
 Calculate factorial N where N! = 1 * 2 * 3 * … * N.
Algorithm: Flowchart:
1. Start
2. Read N
3. Initialize F = 1, I = 1
4. F=F*i
5. Increment i by 1
6. Repeat steps 4 and 5 until i = N
7. Print F
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 53


Algorithm and Flowchart Examples
 Find the sum of n natural numbers.
Algorithm: Flowchart:
1. Start
2. Read n
3. Initialize Count = 0, Sum = 0
4. Count = Count + 1
5. Sum = Sum + Count
6. Repeat steps 4 until 5 until Count > n
7. Print sum
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 54


Algorithm and Flowchart Examples
 Find the sum of all even numbers up to ‘n’.
Algorithm: Flowchart:
1. Start
2. Read n
3. Initialize Count = 0, Sum = 0
4. Count = count + 2
5. Sum = Sum + Count
6. Repeat steps 4 and 5 until count >= n
7. Print Sum
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 55


Algorithm and Flowchart Examples
 Find the product of N numbers.
Algorithm: Flowchart:
1. Start
2. Read n
3. Initialize Count = 0, Product = 1
4. Count = Count + 1
5. Product = Product * Count
6. Repeat steps 4 and 5 until count > N
7. Print Product
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 56


Algorithm and Flowchart Examples
 Find the sum of squares of n natural numbers.
Algorithm: Flowchart:
1. Start
2. Read n
3. Initialize i = 0, Sum = 0
4. i=i+1
5. Sum = Sum + (i * i)
6. Repeat steps 4 and 5 until i > n
7. Print Sum
8. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 57


Algorithm and Flowchart Examples
 Find the sum of first 50 odd numbers.
Algorithm: Flowchart:
1. Start
2. Initialize Sum = 0, N = 1
3. Sum= Sum + N
4. N=N+2
5. Repeat steps 3 and 4 until N <= 99
6. Print Sum
7. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 58


Algorithm and Flowchart Examples
 Calculate percentage of marks.
Algorithm: Flowchart:
1. Start
2. Read Input data
3. Add marks of all subjects giving total
Obtained Marks
4. Percentage = ∗ 100
Total Marks
5. Write Percentage
6. Stop

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 59


Algorithm and Flowchart Examples
 Flowchart to find whether given number is odd or even.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 60


Algorithm and Flowchart Examples
 Flowchart to find maximum number from three different numbers.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 61


Algorithm and Flowchart Examples
 Flowchart to find root of equation: ax2 + bx + c.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 62


Algorithm and Flowchart Examples
 Flowchart to reverse given number.

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 63


Algorithm and Flowchart Examples
 Flowchart to generate Fibonacci series up to given term..

Mr. Viral H. Panchal FOP  Unit 1 – Introduction to Computer Programming 64

You might also like