Download as ppsx, pdf, or txt
Download as ppsx, pdf, or txt
You are on page 1of 104

Introduction to

programming

Prepared by:
Vishal Koshti
1
Introduction

Programming is an art, and to learn art we should learn how to make art.
Similarly, programming cannot be learnt just by knowing or reading syntax of a
particular programming language.
To learn programming, one must write programs on computer.
It is very necessary to know basic requirement of programming and basics of
programming before going directly for practical.
This basic knowledge is really helpful, once real programming using a language is
started.
There are different types of programming languages like,
1. Machine language programming
2. Assembly language programming
3. Higher level language programming
We can use programming to get the solution of given problem.
Algorithm and Flowchart are ways to get the solution of problem.

2
Introduction

Initially people use algorithm and flowchart for the solution purpose.
Algorithm is step by step solution of given problem.
Flowchart is graphical representation of given problem.
Explanation of different types of languages is mentioned below.

3
Types of programming languages

1. Machine language programming


Machine language is the lowest and most elementary level of programming
language and was the first type of programming language to be developed.
Machine language is basically the only language that a computer can understand
and it is usually written in hex.
In fact, a manufacturer designs a computer to obey just one language, its machine
code, which is represented inside the computer by a string of binary digits (bits) 0
and 1.
The symbol 0 stands for the absence of an electric pulse and the 1 stands for the
presence of an electric pulse.
Since a computer is capable of recognizing electric signals, it understands machine
language.

4
Types of programming languages

Machine language example


Below is an example of machine language (binary) for the text "Hello".
01001000 01100101 01101100 01101100 01101111

Advantages of machine language programming


A. Machine language makes fast and efficient use of the computer.
B. It requires no translator to translate the code. It is directly understood by the
computer.

Disadvantages of machine language programming


A. All operation codes have to be remembered.
B. All memory addresses have to be remembered.
C. It is hard to find errors in a program written in the machine language.

5
Types of programming languages

2. Assembly Language
Assembly language was developed to overcome some of the many inconveniences
of machine language.
This is another low-level but very important language in which operation codes
and operands are given in the form of alphanumeric symbols instead of 0’s and 1’s.
These alphanumeric symbols are known as mnemonic codes and can combine in a
maximum of five-letter combinations e.g. ADD for addition, SUB for subtraction,
START, LABEL etc.
Because of this feature, assembly language is also known as “Symbolic
Programming Language”.
This language is also very difficult and needs a lot of practice to master it because
there is only a little English support in this language.
Mostly assembly language is used to help in compiler orientations.
The instructions of the assembly language are converted to machine codes by a
language translator - Assembler and vice versa.

6
Types of programming languages

Assembly language example


mov eax,1
xor ebx,ebx
xor edx,edx
L1:
add eax,ebx
mov ebx,edx
mov edx,eax
loop L1

Advantages of assembly language example


A. Assembly language is easier to understand and use as compared to machine
language.

7
Types of programming languages

B. It is easy to locate and correct errors.


C. It is easily modified.

Disadvantages of assembly language


A. Like machine language, it is also machine dependent/specific.
B. Since it is machine dependent, the programmer also needs to understand the
hardware.
C. It is slower than machine level language because it needs time to convert assembly
language into binary language.

8
Types of programming languages

3. High level languages


High-level computer languages use formats that are similar to English.
The purpose of developing high-level languages was to enable people to write
programs easily, in their own native language environment (English).
High-level languages are basically symbolic languages that use English words
and/or mathematical symbols rather than mnemonic codes.
Each instruction in the high-level language is translated into many machine
language instructions that the computer can understand with the help of compiler
or interpreter.

9
Types of programming languages

Advantages of high level languages


A. High-level languages are user-friendly.
B. They are similar to English and use English vocabulary and well-known symbols.
C. They are easier to learn and to maintain.
D. They are problem-oriented rather than “machine-based”.
E. A program written in a high-level language can be translated into many machine
languages and can run on any computer for which there exists an appropriate
translator.
F. The language is independent of the machine on which it is used i.e. programs
developed in a high-level language can be run on any computer text.

Disadvantages of high level languages


A. A high-level language has to be translated into the machine language by a
translator, which takes up time.

10
Types of programming languages

Compiler Interpreter
Scans the entire program and translates it Translates program one statement at a
as a whole into machine code. time.
It takes large amount of time to analyze It takes less amount of time to analyze the
the source code but the overall execution source code but the overall execution
time is comparatively faster. time is slower.
Generates intermediate object code No intermediate object code is generated,
which further requires linking, hence hence are memory efficient.
requires more memory.
It generates the error message only after Continues translating the program until
scanning the whole program. Hence the first error is met, in which case it
debugging is comparatively hard. stops. Hence debugging is easy.
Programming language like C, C++ use Programming language like Python, Ruby
compilers. use interpreters.

11
Characteristics of higher level
language

There are many higher level languages are available in the computer world like C,
C++, Java, C#, .NET, Php etc.
Among all these languages there are some characteristics which are common to all
the languages which are listed below.
1. Interactive
2. Variety of data types
3. Rich set of operators
4. Flexible control structures
5. Readability
6. Modularity
7. File handling
8. Memory management
9. Interface to other languages
10.Availability of library support

12
Characteristics of higher level
language
1. Interactive
Interactive means two way communication.
Most of the higher level languages are interactive with user, they allow user to
interact with program through input output devices while program is executing.
In c through library functions we can interact with input output devices like
<stdio.h>.
For example, printf() function is used to display the message on console and scanf()
function is used to take input from the keyboard.

2. Variety of data types


A unique objective of any program written in any programming language is to
process the data.
Different kinds of information needs different types of data to be processed, for
that language should provide variety of different data types.

13
Characteristics of higher level
language
Data types are divided into two categories,
A. Basic data types
B. User defined data types
Basic data types are those data types which are provided by language itself to
store characters, integers and real values.
User defined data types are those data types which are defined by user to store
complex information.
Examples of user defined data types are array, structure, union, class etc.
C language supports five basic data types,
A. void
B. char
C. int
D. float
E. double

14
Characteristics of higher level
language
C language has four data type qualifiers to extend the range and values.
A. short
B. long
C. signed
D. unsinged

3. Rich set of operators


An operator defines operation to be performed on data.
For example, + operator is used to add two numbers.
There are different types of operators like arithmetic operators, relational
operators, logical operators, bitwise operators etc.
More number of operators means more different kinds of operation we can
perform.
Language to language set of operators may vary.

15
Characteristics of higher level
language
4. Flexible control structures
The control structures are providing necessary mechanism for implementing
algorithms in language formats.
The structure programming languages provide mainly three types of controls
which are,
A. Sequence
B. Selection or decision
C. Repetition or looping
Any problem includes any kind of operations, to get the solution of problem
respective language should provide above control structure.

A. Sequence
Almost all programming languages supports sequence control structure.
It means that execute the set instruction line by line, one by one.

16
Characteristics of higher level
language
B. Selection or decision
While solving any problem it might be possible that we end up at such situation
where we can execute one flow from two different flow.
So in such case we need to take decision where to go?
Either on left side or right side.
C support different kinds of mechanism through which we can make decision
depends on give situation,
a. only if
b. if-else
c. nested if
d. if-else-if ladder
e. switch case

17
Characteristics of higher level
language
C. Repetition or looping
In programming language it is also possible that we need to execute some set of
instruction again and again.
So instead of writing same lines of code again and again we can put such
statement inside the loop.
C supports three different types of loops,
a. for loop
b. while loop
c. do....while loop

5. Readability
A comment is a sentence which explains some aspect of a program segment or
statement.

18
Characteristics of higher level
language
Thus, the comments help in process of reading and understanding programs.
For example, at the beginning user may write problem statement as comment
which explains the purpose for which program is written.
In C comment is written in /*….*/.
Anything written between /* and */, is considered as comment and removed
during compilation process as comments are not part of program.
They are written just for improving readability of a program.

6. Modularity
As the size and complexity increases, developing a single large program is too
difficult.
It is also unmanageable, even once it is developed.
Programming languages support concept known as modularity in order to handle
size and complexity effectively.

19
Characteristics of higher level
language
Modularity is nothing but dividing large program into collection of small
subroutines.
Each subroutine is itself a small program and perform well defined task.
Modularity not only reduces development complexity, but also reduces complexity
of managing the code i.e. changes, bug fixing, increasing functionalities etc.
In C programming, function is a vehicle to support modularity.
Any C program is a collection of one or more functions.
As function is small and performing specified task, it is easy to write and
understand also.

7. File handling
In many applications, input to program is taken from another file which is already
available or output of program is stored in file for future use.

20
Characteristics of higher level
language
If output of the program is stored in a file, it can be transferred to other machine
through a disk.
For example, in payroll application it is not possible that every time when program
runs, all the details about employees are entered again.
Rather, details are kept in a file which is read by program when runs and changes
made during execution are stored into file so that when program runs again, it
starts with latest detail.
In C programming, file management is supported through rich set of file handling
function which allows user to open a file, read from a file, write into file etc.

8. Memory management
Memory management covers the issue of allocating memory dynamically at run
time and deallocating memory during execution of it is no longer required so that
it can be used later for other purpose.

21
Characteristics of higher level
language
The memory management can be supported either through library calls or directly
using system calls.
The C programming supports memory management function in library known as
“<malloc.h>”.
It provides function like “malloc()” to allocate memory dynamically and “free()” to
release the memory.

9. Interface to other languages


Many programming languages support interface to other languages i.e. they
provide extension to other language.
Such interface or extension is very useful for many reasons.
For example C supports interface to assembly languages statements within c
program itself.

22
Characteristics of higher level
language
If then facilitates to access operating system services directly or some critical
portion can be written in assembly for efficiency purpose.

10. Availability of library support


A library is a collection of related functions or subroutines which are available as
part of compiler and can be used in program by making calls to them.
It save time of development plus improves reliability as these functions are well
tested.
Earlier library support with compiler was limited, but in modern compilers, a larger
collection of various types of libraries are made available.
Hence, the word “package” is more used rather than just compiler.
The C compiler are available with rich support of library.
The very common library is standard I/O which provides functions related to
Input/Output.

23
Problem decomposition
and partitioning
The first step in developing a program is to understand the problem for which
program is to be developed.
Unless until problem is not clearly understood, program cannot be developed or it
may be developed incorrectly.
The size and complexity of problem are two major factors which needs to be
considered while understanding a problem and developing a solution.
A small and simple problem can be understood easily, while large and complex
problem requires some proper method or procedure to simplify it in order to get
its details and to find solution.
One of the well-known and widely used method is decomposition or partitioning
of a problem.
In decomposition or partitioning, given problem which is very difficult to
understand as single piece is divided into sub problems.
Each sub problem then can be further divided into smaller problems.

24
Problem decomposition
and partitioning
This process is repeated until, you get a set of subproblems which are small, easy
to understand and manage.
After developing solution to each small problem, integrating their solutions
properly gives total solution.
The basic idea is to take small part of large problem at a time and solve it.
Solving small problems is easier than considering whole problem at a time.
The decomposition must be done on logical basis not on physical basis.
Consider an example of banking system mentioned below.

25
Problem decomposition
and partitioning
Banking system

Account Loan Employee


management management management

House Vehicle Study


loan loan loan

Saving Current
Payroll Leave
account account
Figure: Decomposition of banking system

26
Problem decomposition
and partitioning
As shown in following figure, one of the major functions of bank is to manage the
various types of accounts like saving, current, loan etc.
Within a loan account, there are various types of loans like housing, vehicle etc.
Another major function of bank is to manage their personal resources which cover
payroll, leave and other information.
Note that it is very difficult to understand even whole accounts management as a
single function.
Rather at a time, if we take only housing load problem in hand, we can easily
understand its rules and regulations.
Once you understand all small problems which are results of decomposition,
problem is solved.
In this, example, decomposition is made on basis of functionality of bank.

27
Problem solving methods

Once a problem is understood, next step is to develop a solution which later can
be translated to a program.
We will take here advantage of decomposition made as a first step.
For each decomposed sub problem, a solution is developed in order to simplify the
work.
Solution of each sub problem is then translated to a sub program.
Resulting set of sub programs are then integrated to form a single large program or
software.
There are widely used problem solving methods.
1. Algorithms
2. Flowcharts

28
Problem solving methods

1. Algorithms
An algorithm is a stepwise solution to a problem.
Each step in an algorithm represents a solution to a small problem.
Hence, algorithm gives a sequence of steps which makes complete solution of a
problem in hand.
An algorithm itself is decomposition of problem into small steps which are easily
understandable.
Following are the examples of algorithms.

29
Algorithm – 001

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to display AIM Computer Academy.
Algorithm number : 001
*/

Step 01: Start


Step 02: [Display message]
Display "AIM Computer Academy"
Step 03: Stop

30
Algorithm – 002

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm for the addition of two integer number.
Algorithm number : 002
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num1 <- 0, num2 <- 0, ans <- 0
Step 03: [Take input from the user]
Display "Enter first number : "
Read num1

31
Algorithm – 002

Display "Enter second number : "


Read num2
Step 04: [Process]
ans <- num1 + num2
Step 05: [Display the output]
Display "Addition is : ", ans
Step 06: Stop

32
Algorithm – 003

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm for the subtraction of two integer number.
Algorithm number : 003
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num1 <- 0, num2 <- 0, ans <- 0
Step 03: [Take input from the user]
Display "Enter first number : "
Read num1

33
Algorithm – 003

Display "Enter second number : "


Read num2
Step 04: [Process]
ans <- num1 - num2
Step 05: [Display the output]
Display "Subtraction is : ", ans
Step 06: Stop

34
Algorithm – 004

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm for the multiplication of two integer number.
Algorithm number : 004
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num1 <- 0, num2 <- 0, ans <- 0
Step 03: [Take input from the user]
Display "Enter first number : "
Read num1

35
Algorithm – 004

Display "Enter second number : "


Read num2
Step 04: [Process]
ans <- num1 * num2
Step 05: [Display the output]
Display "Multiplication is : ", ans
Step 06: Stop

36
Algorithm – 005

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm for the division of two integer number.
Algorithm number : 005
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num1 <- 0, num2 <- 0, ans <- 0
Step 03: [Take input from the user]
Display "Enter first number : "
Read num1

37
Algorithm – 005

Display "Enter second number : "


Read num2
Step 04: [Process]
ans <- num1 / num2
Step 05: [Display the output]
Display "Division is : ", ans
Step 06: Stop

38
Algorithm – 006

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find area of circle.
Algorithm number : 006
*/

Step 01: Start


Step 02: [Declaration and Initialization]
PI <- 3.14, radius <- 0.0, area <- 0.0
Step 03: [Take input from the user]
Display "Enter the value of radius : "
Read radius

39
Algorithm – 006

Step 04: [Process]


area <- PI * radius * radius
Step 05: [Display the output]
Display "Area of circle is : ", area
Step 06: Stop

40
Algorithm – 007

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find area of square.
Algorithm number : 007
*/

Step 01: Start


Step 02: [Declaration and Initialization]
side <- 0.0, area <- 0.0
Step 03: [Take input from the user]
Display "Enter the value of side : "
Read side

41
Algorithm – 007

Step 04: [Process]


area <- side * side
Step 05: [Display the output]
Display "Area of square is : ", area
Step 06: Stop

42
Algorithm – 008

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find area of rectangle.
Algorithm number : 008
*/

Step 01: Start


Step 02: [Declaration and Initialization]
length <- 0.0, width <- 0.0, area <- 0.0
Step 03: [Take input from the user]
Display "Enter the value of length : "
Read length

43
Algorithm – 008

Display "Enter the value of width : "


Read width
Step 04: [Process]
area <- length * width
Step 05: [Display the output]
Display "Area of rectangle is : ", area
Step 06: Stop

44
Algorithm – 009

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find area of triangle.
Algorithm number : 009
*/

Step 01: Start


Step 02: [Declaration and Initialization]
breadth <- 0.0, height <- 0.0, area <- 0.0
Step 03: [Take input from the user]
Display "Enter the value of breadth : "
Read breadth

45
Algorithm – 009

Display "Enter the value of height : "


Read height
Step 04: [Process]
area <- 0.5 * breadth * height
Step 05: [Display the output]
Display "Area of triangle is : ", area
Step 06: Stop

46
Problem solving methods

2. Flowcharts
A flowchart is a special representation of an algorithm.
As it represents solution in form of picture, it is more easier to understand and
develop.
A main advantage of flowchart is visibility of paths within solution.
Each path (or logical sequence) is clearly visible as arrows are used to represent
flow.
Before developing flowcharts for example problems, different flowchart symbols
must be known.
They are shows in following figure.

47
Problem solving methods

Start / Stop Decision making

Input / Output
Page break

Process or
Computation Continue

Sub-routine
Arrows

48
Flowchart – 001

Start

Display “AIM
Computer
Academy”

Stop
Figure: Flowchart to display the message

49
Flowchart – 002

Start

num1 <- 0, num2 <- 0, ans <- 0

Input num1
Input num2

ans <- num1 + num2

Display ans

Stop
Figure: Flowchart to display the addition of two integer numbers

50
Flowchart – 003

Start

num1 <- 0, num2 <- 0, ans <- 0

Input num1
Input num2

ans <- num1 - num2

Display ans

Stop
Figure: Flowchart to display the subtraction of two integer numbers

51
Flowchart – 004

Start

num1 <- 0, num2 <- 0, ans <- 0

Input num1
Input num2

ans <- num1 * num2

Display ans

Stop
Figure: Flowchart to display the multiplication of two integer numbers

52
Flowchart – 005

Start

num1 <- 0, num2 <- 0, ans <- 0

Input num1
Input num2

ans <- num1 / num2

Display ans

Stop
Figure: Flowchart to display the division of two integer numbers

53
Flowchart – 006

Start

PI <- 3.14, radius <- 0.0, area <- 0.0

Input radius

area <- PI * radius * radius

Display area

Stop
Figure: Flowchart to find area of circle

54
Flowchart – 007

Start

side <- 0.0, area <- 0.0

Input side

area <- side * side

Display area

Stop
Figure: Flowchart to find area of square

55
Flowchart – 008

Start

length <- 0.0, width <- 0.0, area <- 0.0

Input length
Input width

area <- length * width

Display area

Stop
Figure: Flowchart to find area of rectangle

56
Flowchart – 009

Start

breadth <- 0.0, height <- 0.0, area <- 0.0

Input breadth
Input height

area <- 0.5 * breadth * height

Display area

Stop
Figure: Flowchart to find area of triangle

57
Algorithm – 010

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find maximum number from the two numbers.
Algorithm number : 010
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num1 <- 0, num2 <-0
Step 03: [Take input from the user]
Display "Enter first number : "
Read num1

58
Algorithm – 010

Display "Enter second number : "


Read num2
Step 04: [Find maximum number]
If num1 > num2 Then
Display "First number is maximum"
Else
Display "Second number is maximum"
End if
Step 05: Stop

59
Algorithm – 011

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find minimum number from the two numbers.
Algorithm number : 011
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num1 <- 0, num2 <-0
Step 03: [Take input from the user]
Display "Enter first number : "
Read num1

60
Algorithm – 011

Display "Enter second number : "


Read num2
Step 04: [Find minimum number]
If num1 < num2 Then
Display "First number is minimum"
Else
Display "Second number is minimum"
End if
Step 05: Stop

61
Algorithm – 012

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to check whether entered number is positive or
negative.
Algorithm number : 012
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num <- 0
Step 03: [Take input from the user]
Display "Enter any number : "
Read num

62
Algorithm – 012

Step 04: [Checking whether number is positive or negative]


If num >= 0 Then
Display "Entered number is positive"
Else
Display "Entered number is negative"
End if
Step 05: Stop

63
Algorithm – 013

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to check whether entered number is even or odd.
Algorithm number : 013
*/

Step 01: Start


Step 02: [Declaration and Initialization]
num <- 0
Step 03: [Take input from the user]
Display "Enter any number : "
Read num

64
Algorithm – 013

Step 04: [Checking whether number is even or odd]


If num % 2 = 0 Then
Display "Entered number is even"
Else
Display "Entered number is odd"
End if
Step 05: Stop

65
Flowchart – 010

Start

num1 <- 0, num2 <- 0

Input num1
Input num2

Second number No Is num1 > Yes First number is


is maximum num2? maximum

Stop
Figure: Flowchart to find maximum number from two numbers

66
Flowchart – 011

Start

num1 <- 0, num2 <- 0

Input num1
Input num2

Second number No Is num1 < Yes First number is


is minimum num2? minimum

Stop
Figure: Flowchart to find minimum number from two numbers

67
Flowchart – 012

Start

num <- 0

Input num

Number is No Is num >= Yes Number is


negative 0? positive

Stop
Figure: Flowchart to check whether number is positive or negative

68
Flowchart – 013

Start

num <- 0

Input num

No Is num % Yes
Number is odd Number is even
2=0?

Stop
Figure: Flowchart to check whether number is even or odd

69
Algorithm – 014

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find maximum number from the three numbers.
Algorithm number : 014
*/

Step 01: Start


Step 02: [Declaration and Initialization]
n1 <- 0, n2 <-0, n3 <- 0
Step 03: [Take input from the user]
Display "Enter first number : "
Read n1

70
Algorithm – 014

Display "Enter second number : "


Read n2
Display "Enter third number : "
Read n3
Step 04: [Check for maximum number]
If n1 > n2 Then
Go to Step-05
Else
Go to Step-06
End if
Step 05: [Check for maximum number]
If n1 > n3 Then
Go to Step-07

71
Algorithm – 014

Else
Go to Step-09
End if
Step 06: [Check for maximum number]
If n2 > n3 Then
Go to Step-08
Else
Go to Step-09
End if
Step 07: [Display the output]
Display "First number is maximum"
Go to Step-10
Step 08: [Display the output]

72
Algorithm – 014

Display "Second number is maximum"


Go to Step-10
Step 09: [Display the output]
Display "Third number is maximum"
Step 10: Stop

73
Algorithm – 015

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to find minimum number from the three numbers.
Algorithm number : 015
*/

Step 01: Start


Step 02: [Declaration and Initialization]
n1 <- 0, n2 <-0, n3 <- 0
Step 03: [Take input from the user]
Display "Enter first number : "
Read n1

74
Algorithm – 015

Display "Enter second number : "


Read n2
Display "Enter third number : "
Read n3
Step 04: [Check for minimum number]
If n1 < n2 Then
Go to Step-05
Else
Go to Step-06
End if
Step 05: [Check for minimum number]
If n1 < n3 Then
Go to Step-07

75
Algorithm – 015

Else
Go to Step-09
End if
Step 06: [Check for minimum number]
If n2 < n3 Then
Go to Step-08
Else
Go to Step-09
End if
Step 07: [Display the output]
Display "First number is minimum"
Go to Step-10
Step 08: [Display the output]

76
Algorithm – 015

Display "Second number is minimum"


Go to Step-10
Step 09: [Display the output]
Display "Third number is minimum"
Step 10: Stop

77
Flowchart – 014
Start

n1 <- 0, n2 <- 0, n3 <- 0

Input n1, n2 and n3

No Is n1 Yes
> n2?
No Is n2 Yes No Is n1 Yes
> n3? > n3?

n3 n2 n3 n1
maximum maximum maximum maximum

Figure: Flowchart to find maximum


Stop
number from three numbers

78
Flowchart – 015
Start

n1 <- 0, n2 <- 0, n3 <- 0

Input n1, n2 and n3

No Is n1 Yes
< n2?
No Is n2 Yes No Is n1 Yes
< n3? < n3?

n3 n2 n3 n1
minimum minimum minimum minimum

Figure: Flowchart to find minimum


Stop
number from three numbers

79
Algorithm – 016

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to print the grade of the student according to the
percentage.
Algorithm number : 016
*/

Step 01: Start


Step 02: [Declaration and Initialization]
percentage <- 0.0, grade <- '\0'
Step 03: [Take input from the user]
Display "Enter the value of percentage : "

80
Algorithm – 016

Read percentage
Step 04: [Assign grade]
If percentage > 90 Then
grade <- 'A'
Go to step-09
Else
Go to step-05
End if
Step 05: [Assign grade]
If percentage > 80 Then
grade <- 'B'
Go to step-09
Else

81
Algorithm – 016

Go to step-06
End if
Step 06: [Assign grade]
If percentage > 70 Then
grade <- 'C'
Go to step-09
Else
Go to step-07
End if
Step 07: [Assign grade]
If percentage > 60 Then
grade <- 'D'
Go to step-09

82
Algorithm – 016

Else
Go to step-08
End if
Step 08: [Assign grade]
If percentage > 50 Then
grade <- 'E'
Else
grade <- 'F'
End if
Step 09: [Display the grade]
Display "The grade of the student is : ", grade
Step 10: Stop

83
Flowchart – 016
Start

percentage <- 0.0, grade <- ‘\0’

Read percentage

Is
Yes
percentage > grade <- ‘A’ 2
90
No
Is
Yes
percentage > grade <- ‘B’ 2
80
No
1 Figure: Flowchart to display the grade

84
Flowchart – 016

Is
Yes
1 percentage > grade <- ‘C’
70
No
Is
Yes
percentage > grade <- ‘D’
60
No
Is
Yes
percentage > grade <- ‘E’
50
No
grade <- ‘F’ Display grade

Figure: Flowchart to display the grade Stop 2

85
Algorithm – 017

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to display first 10 natural numbers.
Algorithm number : 017
*/

Step 01: Start


Step 02: [Declaration and Initialization]
i <- 1
Step 03: [Display the numbers]
Repeat Step-03 while i <= 10
Display "The number is : ", i

86
Algorithm – 017

i <- i + 1
End while
Step 04: Stop

87
Algorithm – 018

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to add first 10 natural numbers.
Algorithm number : 018
*/

Step 01: Start


Step 02: [Declaration and Initialization]
i <- 1, sum <- 0
Step 03: [Perform the addition]
Repeat Step-03 while i <= 10
sum <- sum + i

88
Algorithm – 018

i <- i + 1
End while
Step 04: [Display the output]
Display "Sum of first 10 natural number is : ", sum
Step 05: Stop

89
Algorithm – 019

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to add first 10 even natural numbers.
Algorithm number : 019
*/

Step 01: Start


Step 02: [Declaration and Initialization]
i <- 2, sum <- 0
Step 03: [Perform the addition]
Repeat Step-03 while i <= 20
sum <- sum + i

90
Algorithm – 019

i <- i + 2
End while
Step 04: [Display the output]
Display "Sum of first 10 even natural number is : ", sum
Step 05: Stop

91
Algorithm – 020

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to add first 10 odd natural numbers.
Algorithm number : 020
*/

Step 01: Start


Step 02: [Declaration and Initialization]
i <- 1, sum <- 0
Step 03: [Perform the addition]
Repeat Step-03 while i <= 19
sum <- sum + i

92
Algorithm – 020

i <- i + 2
End while
Step 04: [Display the output]
Display "Sum of first 10 odd natural number is : ", sum
Step 05: Stop

93
Algorithm – 021

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to add first 10 numbers entered by user.
Algorithm number : 021
*/

Step 01: Start


Step 02: [Declaration and Initialization]
i <- 1, num <- 0, sum <- 0
Step 03: [Take the input and perform the addition]
Repeat Step-03 while i <= 10
Display "Enter any number : "

94
Algorithm – 021

Read num
sum <- sum + num
i <- i + 1
End while
Step 04: [Display the output]
Display "Sum of 10 numbers entered by user is : ", sum
Step 05: Stop

95
Algorithm – 022

/*
AIM Computer Academy
Author name : Vishal Koshti
Algorithm : Write an algorithm to print Fibonacci series up to N terms.
Algorithm number : 022
*/

Step 01: Start


Step 02: [Declaration and Initialization]
i <- 3, firstTerm <- 0, secondTerm <- 1, thirdTerm <- 0, terms <- 0
Step 03: [Take input from the user]
Display "Enter number of terms : "
Read terms

96
Algorithm – 022

Step 04: [Display first two terms]


Display firstTerm
Display secondTerm
Step 05: [Display Fibonacci series]
Repeat Step-05 while (i <= terms)
thirdTerm <- firstTerm + secondTerm
Display thirdTerm
firstTerm <- secondTerm
secondTerm <- thirdTerm
i <- i + 1
End while
Step 06: Stop

97
Flowchart – 017

Start

i <- 1

No
Is i <= 10?

Yes
Display i

i <- i + 1

Stop
Figure: Flowchart to print first 10 natural numbers

98
Flowchart – 018

Start

i <- 0, sum <- 0

No
Is i <= 10?

Yes
sum <- sum + i
Display sum
i <- i + 1

Stop

Figure: Flowchart to add first 10 natural numbers

99
Flowchart – 019

Start

i <- 2, sum <- 0

No
Is i <= 20?

Yes
sum <- sum + i
Display sum
i <- i + 2

Stop

Figure: Flowchart to add first 10 even natural numbers

100
Flowchart – 020

Start

i <- 1, sum <- 0

No
Is i <= 19?

Yes
sum <- sum + i
Display sum
i <- i + 2

Stop

Figure: Flowchart to add first 10 odd natural numbers

101
Flowchart – 021

Start

i <- 1, sum <- 0, num <- 0

No
Is i <= 10?

Yes
Input num
Display sum

sum <- sum + num


i <- i + 1

Stop
Figure: Flowchart to add first 10 numbers entered by user

102
Flowchart – 022

Start

Figure: Flowchart to display Fibonacci series up to


i<-3, firstTerm<-0, secondTerm<-1, thirdTerm<-0, terms<-0

Input terms

Display firstTerm, secondTerm

N terms
Is i <= No
Stop
terms?
Yes
thirdTerm <- firstTerm + secondTerm

Display thirdTerm

firstTerm <- secondTerm


secondTerm <- thirdTerm
i <- i + 1
103
Questions…?

AIM Computer Academy


: 7600 332 003, 7600 332 008
: vishalkoshti.aim@gmail.com
104
: www.aimacademy.co.in

You might also like