UNIT I COMPUTATIONAL THINKING AND PROBLEM SOLVING - Fundamentals of
Computing – Identification of Computational Problems -Algorithms, building blocks of algorithms
(statements, state, control flow, functions), notation (pseudo code, flow chart, programming language),
algorithmic problem solving, simple strategies for developing algorithms (iteration, recursion). Illustrative
problems: find minimum in a list, insert a card in a list of sorted cards, guess an integer number in a
range, Towers of Hanoi.
Computational problem
In theoretical computer science, a computational problem is a problem that a computer might be able to
solve or a question that a computer may be able to answer. For example, the problem of factoring
"Given a positive integer n, find a nontrivial prime factor of n."
is a computational problem. A computational problem can be viewed as a set of instances or cases
together with a, possibly empty, set of solutions for every instance/case. For example, in the factoring
problem, the instances are the integers n, and solutions are prime numbers p that describe nontrivial prime
factors of n.
Computational problems are one of the main objects of study in theoretical computer science. The field of
computational complexity theory attempts to determine the amount of resources (computational
complexity) solving a given problem will require and explain why some problems are intractable or
undecidable. Computational problems belong to complexity classes that define broadly the resources (e.g.
time, space/memory, energy, circuit depth) it takes to compute (solve) them with various abstract
machines. For example, the complexity class P for classicalmachines, and BQP for quantum machines.
It is typical of many problems to represent both instances and solutions by binary strings, namely
elements of {0, 1}*.[a] For example, numbers can be represented as binary strings using binary encoding.
Types
A decision problem is a computational problem where the answer for every instance is either yes or no.
An example of a decision problem is primality testing:
"Given a positive integer n, determine if n is prime."
A decision problem is typically represented as the set of all instances for which the answer is yes. For
example, primality testing can be represented as the infinite set
L = {2, 3, 5, 7, 11, ...}
In a search problem, the answers can be arbitrary strings. For example, factoring is a search problem
where the instances are (string representations of) positive integers and the solutions are (string
representations of) collections of primes.
A search problem is represented as a relation consisting of all the instance-solution pairs, called a search
relation. For example, factoring can be represented as the relation
1
R = {(4, 2), (6, 2), (6, 3), (8, 2), (9, 3), (10, 2), (10, 5)...}
which consist of all pairs of numbers (n, p), where p is a nontrivial prime factor of n.
A counting problem asks for the number of solutions to a given search problem. For example, a counting
problem associated with factoring is
"Given a positive integer n, count the number of nontrivial prime factors of n."
A counting problem can be represented by a function f from {0, 1}* to the nonnegative integers. For a
search relation R, the counting problem associated to R is the function
fR(x) = |{y: R(x, y) }|.
An optimization problem asks for finding a "best possible" solution among the set of all possible solutions
to a search problem. One example is the maximum independent set problem:
"Given a graph G, find an independent set of G of maximum size."
Optimization problems can be represented by their search relations.
In a function problem a single output (of a total function) is expected for every input, but the output is
more complex than that of a decision problem, that is, it isn't just "yes" or "no". One of the most famous
examples is the traveling salesman problem:
"Given a list of cities and the distances between each pair of cities, find the shortest possible route that
visits each city exactly once and returns to the origin city."
It is an NP-hard problem in combinatorial optimization, important in operations research and theoretical
computer science.
Algorithm
Definition: An algorithm is procedure consisting of a finite set of unambiguous rules (instructions) which
specify a finite sequence of operations that provides the solution to a problem. In other word, an
algorithm is a step-by-step procedure to solve a given problem
Definition: An algorithm is a finite number of clearly described, unambiguous “double” steps that can be
systematically followed to produce a desired result for given input in a finite amount of time.
Building blocks of algorithm
It has been proven that any algorithm can be constructed from just three basic building blocks. These
three building blocks are Sequence, Selection, and Iteration.
2
Building Block Common name
Sequence Action
Selection Decision
Iteration Repetition or Loop
A sequence is one of the basic logic structures in computer programming. In a sequence structure, an
action, or event, leads to the next ordered action in a predetermined order. The sequence can contain any
number of actions, but no actions can be skipped in the sequence. Once running, the program must
perform each action in order without skipping any.
A selection (also called a decision) is also one of the basic logic structures in computer programming. In a
selection structure, a question is asked, and depending on the answer, the program takes one of two
courses of action, after which the program moves on to the next event.
An iteration is a single pass through a group/set of instructions. Most programs often contain loops of
instructions that are executed over and over again. The computer repeatedly executes the loop, iterating
through the loop
E.g.
Write an algorithm to add two numbers entered by user.
Step 1: Start
Step 2: Read A,B
Step 3: Compute C = A + B
Step 4: Display C
Step 6: Stop
Write an algorithm to find the largest among three different numbers entered by user.
Step 1: Start
Step 2: Read variables a, b and c.
Step 4: If a>b and a>c
Display a is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
3
Write an algorithm to find the factorial of a number entered by user.
Step 1: Start
Step 2: factorial←1
Step 3: i←1
Step 4: Read n
Step 5: Repeat the steps till i=n
5.1: factorial←factorial*i
5.2: i←i+1
Step 6: Display factorial
Step 7: Stop
Statements:
Statement is a single action in a computer.
In a computer statements might include some of the following actions
Input data-information given to the program
Process data-perform operation on a given input
Output data-processed result
State
Transition from one process to another process under specified condition with in a time is called state.
Control flow
The process of executing the individual statements in a given order is called control flow.
The control can be executed in three ways
1.Sequence
2. Selection
3. Iteration
Functions
Function is a sub program which consists of block of code(set of instructions) that performs a
particular task.
For complex problems, the problem is been divided into smaller and simpler tasks during algorithm
design.
Benefits of Using Functions
Reduction in line of code
code reuse
Better readability
Information hiding
Easy to debug and test
Improved maintainability
4
Example:
Algorithm for addition of two numbers using function
Main function()
Step 1: Start
Step 2: Call the function add()
Step 3: Stop
Sub function add()
Step 1: Function start
Step 2: Get a, b Values
Step 3: compute c=a+b
Step 4: Print c
Step 5: Return
NOTATIONS OF ALGORITHM
Pseudocode
Flow Chart
Programming language
PSEUDO CODE
Pseudo code consists of short, readable and formally styled English languages used for explain an
algorithm.
It does not include details like variable declaration, subroutines.
It is easier to understand for the programmer or non programmer to understand the general
working of the program, because it is not based on any programming language.
It gives us the sketch of the program before actual coding.
It is not a machine readable
Pseudo code can’t be compiled and executed.
There is no standard syntax for pseudo code.
Guidelines for writing pseudo code:
Write one statement per line
Capitalize initial keyword
Indent to hierarchy
End multiline structure
Keep statements language independent
5
Common keywords used in pseudocode
The following gives common keywords used in pseudocodes.
1. //: This keyword used to represent a comment.
2. BEGIN,END: Begin is the first statement and end is the last statement.
3. INPUT, GET, READ: The keyword is used to inputting data.
4. COMPUTE, CALCULATE: used for calculation of the result of the given expression.
5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
7. IF, ELSE, ENDIF: used to make decision.
8. WHILE, ENDWHILE: used for iterative statements.
9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.
Example: Greates of two numbers
BEGIN
READ a,b
IF (a>b) THEN
DISPLAY a is greater
ELSE
DISPLAY b is greater
END IF
END
Example: Print n natural numbersusing for
BEGIN
GET n
INITIALIZE i=1
FOR (i<=n) DO
6
PRINT i
i=i+1
ENDFOR
END
Example: Print n natural numbers using while
BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+1
ENDWHILE
END
Advantages:
Pseudo is independent of any language; it can be used by most programmers.
It is easy to translate pseudo code into a programming language.
It can be easily modified as compared to flowchart.
Converting a pseudo code to programming language is very easy as compared with converting a
flowchart to programming language.
Disadvantages:
It does not provide visual representation of the program’s logic.
There are no accepted standards for writing pseudo codes.
It cannot be compiled nor executed.
For a beginner, It is more difficult to follow the logic or write pseudo code ascompared to flowchart.
FLOW CHART
Flow chart is defined as graphical representation of the logic for problem solving.
The purpose of flowchart is making the logic of the program clear in a visual representation.
7
Rules for drawing a flowchart
1. The flowchart should be clear, neat and easy to follow.
2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
4. Only one flow line should enter a decision symbol. However, two or three flow lines may leave the
decision symbol.
5. Only one flow line is used with a terminal symbol.
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.
8
Advantages of flowchart:
1.Communication: - Flowcharts are better way of communicating the logic of a system to all concerned.
2.Effective analysis: - With the help of flowchart, problem can be analyzed in more effective way.
3.Proper documentation: - Program flowcharts serve as a good program documentation, which is
needed for various purposes.
4.Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis and program
development phase.
5.Proper Debugging: - The flowchart helps in debugging process.
6.Efficient Program Maintenance: - The maintenance of operating program becomes easy with the help
of flowchart. It helps the programmer to put efforts more efficiently on that part.
Disadvantages of flow chart:
1.Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart becomes
complex and clumsy.
2.Alterations and Modifications: - If alterations are required the flowchart may require re-drawing
completely.
3.Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart becomes a
problem.
4.Cost: For large application the time and cost of flowchart drawing becomes costly.
9
PROGRAMMING LANGUAGE
A programming language is a set of symbols and rules for instructing a computer to perform specific
tasks. The programmers have to follow all the specified rules before writing program using programming
language. The user has to communicate with the computer using language which it can understand.
10
Types of programming language
1.Machine language
2. Assembly language
3. High level language
Machine language:The computer can understand only machine language which uses 0’s and 1’s. In
machine language the different instructions are formed by taking different combinations of 0’s and 1’s.
Advantages:
Translation free:Machine language is the only language which the computer understands. For executing
any program written in any programming language, the conversion to machine language is necessary. The
program written in machine language can be executed directly on computer. In this case any conversion
process is not required.
High speed: The machine language program is translation free. Since the conversion time is saved, the
execution of machine language program is extremely fast.
Disadvantage:
It is hard to find errors in a program written in the machine language.
Writhing program in machine language is a time consuming process.
Machine dependent: According to architecture used, the computer differs from each other. So machine
language differs from computer to computer. So a program developed for a particular type of computer
may not run on other type of computer.
Assembly language:
To overcome the issues in programming language and make the programming process easier, an assembly
language is developed which is logically equivalent to machine language but it is easier for people to read,
write and understand.
Assembly language is symbolic representation of machine language. Assembly languages are
symbolic programming language that uses symbolic notation to represent machine language instructions.
They are called low level language because they are so closely related to the machines.
Assembler
Assembler is the program which translates assembly language instruction in to a machine language.
Easy to understand and use.
It is easy to locate and correct errors.
11
Disadvantage
Machine dependent :The assembly language program which can be executed on the machine depends on
the architecture of that computer.
Hard to learn: It is machine dependent, so the programmer should have the hardware knowledge to
create applications using assembly language.
Less efficient:
Execution time of assembly language program is more than machine language program.
Because assembler is needed to convert from assembly language to machine language.
High level language
High level language contains English words and symbols. The specified rules are to be followed while
writing program in high level language. The interpreter or compilers are used for converting these
programs in to machine readable form.
Translating high level language to machine language
The programs that translate high level language in to machine language are called interpreter or compiler.
Compiler:A compiler is a program which translates the source code written in a high level language in to
object code which is in machine language program. Compiler reads the whole program written in high
level language and translates it to machine language. If any error is found it display error message on the
screen.
Interpreter: Interpreter translates the high level language program in line by line manner. The interpreter
translates a high level language statement in a source program to a machine code and executes it
immediately before translating the next statement. When an error is found the execution of the program is
halted and error message is displayed on the screen.
Advantages
Readability :High level language is closer to natural language so they are easier to learn and understand
Machine independent: High level language program have the advantage of being portable between
machines.
Easy debugging: Easy to find and correct error in high level language
Disadvantages
Less efficient: The translation process increases the execution time of the program. Programs in high
level language require more memory and take more execution time to execute.
12
They are divided into following categories:
1.Interpreted programming languages
2. Functional programming languages
3. Compiled programming languages
4. Procedural programming languages
5. Scripting programming language
6. Markup programming language
7.Concurrent programming language
8.Object oriented programming language
Interpreted programming languages:An interpreted language is a programming language for which
most of its implementation executes instructions directly, without previously compiling a program into
machine language instructions. The interpreter executes the program directly translating each statement
into a sequence of one or more subroutines already compiled into machine code.
Examples:
Pascal
Python
Functional programming language:Functional programming language defines every computation as a
mathematical evaluation. They focus on the programming languages are bound to mathematical
calculations
Examples:Clean, Haskell
Compiled Programming language:A compiled programming is a programming language whose
implementation are typically compilers and not interpreters.It will produce a machine code from source
code.
Examples:C, C++, C#, JAVA
Procedural programming language:Procedural (imperative) programming implies specifying the steps
that the programs should take to reach to an intended state.A procedure is a group of statements that can
be referred through a procedure call. Procedures help in the reuse of code. Procedural programming
makes the programs structured and easily traceable for program flow.
Examples:Hyper talk ,MATLAB
Scripting language:Scripting language are programming languages that control an application. Scripts
can execute independent of any other application. They are mostly embedded in the application that they
control and are used to automate frequently executed tasks like communicating with external program.
13
Examples:Apple script, VB script, PHP
Markup languages:A markup language is an artificial language that uses annotations to text that define
hoe the text is to be displayed.
Examples:HTML, XML
Concurrent programming language:Concurrent programming is a computer programming technique
that provides for the execution of operation concurrently, either with in a single computer or across a
number of systems.
Examples: Joule, Limbo
Object oriented programming language:Object oriented programming is a programming paradigm
based on the concept of objects which may contain data in the form of procedures often known as
methods.
Examples:Lava, Moto
ALGORITHMIC PROBLEM SOLVING:
Algorithmic problem solving is solving problem that require the formulation of an algorithm for the
solution.
14
Understanding the Problem
It is the process of finding the input of the problem that the algorithm solves.
It is very important to specify exactly the set of inputs the algorithm needs to handle.
A correct algorithm is not one that works most of the time, but one that works correctly
for all legitimate inputs.
Ascertaining the Capabilities of the Computational Device
If the instructions are executed one after another, it is called sequential algorithm.
If the instructions are executed concurrently, it is called parallel algorithm.
Choosing between Exact and Approximate Problem Solving
The next principal decision is to choose between solving the problem exactly or solving it
approximately.
Based on this, the algorithms are classified as exact algorithm and approximationalgorithm.
Deciding a data structure:
Data structure plays a vital role in designing and analysis the algorithms.
Some of the algorithm design techniques also depend on the structuring data specifying a problem’s
instance
Algorithm+ Data structure=programs.
Algorithm Design Techniques
An algorithm design technique (or “strategy” or “paradigm”) is a general approach to solving
problems algorithmically that is applicable to a variety of problems from different areas of computing.
Learning these techniques is of utmost importance for the following reasons.
First, they provide guidance for designing algorithms for new problems,
Second, algorithms are the cornerstone of computer science
Methods of Specifying an Algorithm
Pseudocode is a mixture of a natural language and programming language-like constructs.
Pseudocode is usually more precise than natural language, and its usage often yields more succinct
algorithm descriptions.
In the earlier days of computing, the dominant vehicle for specifying algorithms was a flowchart, a
method of expressing an algorithm by a collection of connected geometric shapes containing descriptions
of the algorithm’s steps.
Programming language can be fed into an electronic computer directly. Instead, it needs to be
converted into a computer program written in a particular computer language. We can look at such a
program as yet another way ofspecifying the algorithm, although it is preferable to consider it as the
algorithm’s implementation.
15
Proving an Algorithm’s Correctness
Once an algorithm has been specified, you have to prove its correctness. That is, you have to prove
that the algorithm yields a required result for every legitimate input in a finite amount of time.
A common technique for proving correctness is to use mathematical induction because an algorithm’s
iterations provide a natural sequence of steps needed for such proofs.
It might be worth mentioning that although tracing the algorithm’s performance for a few specific
inputs can be a very worthwhile activity, it cannot prove the algorithm’s correctness conclusively. But in
order to show that an algorithm is incorrect, you need just one instance of its input for which the
algorithm fails.
Analysing an Algorithm
1. Efficiency.
Time efficiency, indicating how fast the algorithm runs,
Space efficiency, indicating how much extra memory it uses.
2. simplicity.
An algorithm should be precisely defined and investigated with mathematical expressions.
Simpler algorithms are easier to understand and easier to program.
Simple algorithms usually contain fewer bugs.
Coding an Algorithm
Most algorithms are destined to be ultimately implemented as computer programs. Programming an
algorithm presents both a peril and an opportunity.
A working program provides an additional opportunity in allowing an empirical analysis of the
underlying algorithm. Such an analysis is based on timing the program on several inputs and then
analysing the results obtained
SIMPLE STRATEGIES FOR DEVELOPING ALGORITHMS:
1.Iterations
2. Recursions
1. Iterations:A sequence of statements is executed until a specified condition is true is called iterations.
1.for loop
2.While loop
Syntax for For:
FOR( start-value to end-value) DO
16
Statement
...
ENDFOR
Example: Print n natural numbers
BEGIN
GET n
INITIALIZE i=1
FOR (i<=n) DO
PRINT i
i=i+1
ENDFOR
END
Syntax for While:
WHILE (condition) DO
Statement
...
ENDWHILE
Example: Print n natural numbers
BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+1
ENDWHILE
END
Recursions:
A function that calls itself is known as recursion.
Recursion is a process by which a function calls itself repeatedly until some specified condition has
been satisfied.
17
Algorithm for factorial of n numbers using recursion:
Main function:
Step1: Start
Step2: Get n
Step3: call factorial(n)
Step4: print fact
Step5: Stop
Sub function factorial(n):
Step1: if(n==1) then fact=1 return fact
Step2: else fact=n*factorial(n-1) and return fact
18
Pseudo code for factorial using recursion:
Main function:
BEGIN
GET n
CALL factorial(n)
PRINT fact
END
Sub function factorial(n):
IF(n==1) THEN
fact=1
RETURN fact
ELSE
RETURN fact=n*factorial(n-1)
More examples:
Write an algorithm to find area of a rectangle
Step 1: Start
Step 2: get l,b values
Step 3: Calculate A=l*b
Step 4: Display A
Step 5: Stop
Psuedocode
Begin
Read L,B
Calculate A=L*B
Display A
19
End
Write an Algorithm For Calculating Area And Circumference Of Circle
Step 1: Start
Step 2: Get R Value
Step 3: Calculate A=3.14*R*R
Step 4: Calculate C=2.3.14*R
Step 5: Display A,C
Step 6: Stop
Psuedocode
Begin
Read R
Calculate A And C
A=3.14*R*R
C=2*3.14*R
Display A
20
End
Write An Algorithm For Calculating Simple Interest
Step 1: Start
Step 2: Get P, N, R Value
Step3:Calculate
Si=(P*N*R)/100
Step 4: Display S
Step 5: Stop
Psuedocode
Begin
Read P, N, R
Calculate S
Si=(P*N*R)/100
Display Si
21
End
Write An Algorithm For Calculating Engineering Cutoff
Step 1: Start
Step2: Get P,C,M Value
Step3:Calculate
Cutoff= (P/4+C/4+M/2)
Step 4: Display Cutoff
Step 5: Stop
Psuedocode
Begin
Read P,C,M
Calculate
Cutoff= (P/4+C/4+M/2)
Display Cutoff
22
End
To Check Greatest Of Two Numbers
Step 1: Start
Step 2: Get A,B Value
Step 3: Check If(A>B) Print A Is Greater
Step 4: Else B Is Greater
Step 5: Stop
Psuedocode
Begin
Read A,B
If (A>B) Then
Display A Is Greater
Else
Display B Is Greater
End If
End
23
To Check Leap Year Or Not
Step 1: Start
Step 2: Get Y
Step 3: If(Y%4==0) Print Leap Year
Step 4: Else Print Not Leap Year
Step 5: Stop
Psuedocode
Begin
Read Y
If (Y%4==0) Then
Display Leap Year
Else
Display Not Leap Year
End If
End
24
To Check Positive Or Negative Number
Step 1: Start
Step 2: Get Num
Step 3: Check If(Num>0) Print A Is Positive
Step 4: Else Num Is Negative
Step 5: Stop
Psuedocode
Begin
Read Num
If (Num>0) Then
Display Num Is Positive
Else
Display Num Is Negative
End If
End
25
To Check Odd Or Even Number
Step 1: Start
Step 2: Get Num
Step 3: Check If(Num%2==0) Print Num Is Even
Step 4: Else Num Is Odd
Step 5: Stop
Psuedocode
Begin
Read Num
If (Num%2==0) Then
Display Num Is Even
Else
Display Num Is Odd
End If
End
26
To Check Greatest Of Three Numbers
Step1: Start
Step2: Get A, B, C
Step3: If(A>B) Goto Step4 Else Goto Step5
Step4: If(A>C) Print A Else Print C
Step5: If(B>C) Print B Else Print C
Step6: Stop
Psuedocode
Begin
Read A, B, C
If (A>B) Then
If(A>C) Then
Display A Is Greater
Else
Display C Is Greater
End If
Else
If(B>C) Then
Display B Is Greater
Else
Display C Is Greater
End If
End If
27
End
Write An Algorithm To Check Whether Given Number Is +Ve, -Ve Or Zero.
Step 1: Start
Step 2: Get N Value.
Step 3: If (N ==0) Print “Given Number Is Zero” Else Goto Step4
Step 4: If (N > 0) Then Print “Given Number Is +Ve”
Step 5: Else Print “Given Number Is -Ve”
Step 6: Stop
Begin
Get N
If(N==0) Then
Display “ N Is Zero”
Else
If(N>0) Then
Display “N Is Positive”
Else
Display “N Is Positive”
End If
End If
28
End
Write An Algorithm To Print All Natural Numbers Up To N
Step 1: Start
Step 2: Get N Value.
Step 3: Initialize I=1
Step 4: If (I<=N) Go To Step 5 Else Go To Step 8
Step 5: Print I Value
Step 6 : Increment I Value By 1
Step 7: Go To Step 4
Step 8: Stop
Begin
Get N
Initialize I=1
While(I<=N) Do
Print I
I=I+1
Endwhile
End
29
Write An Algorithm To Print N Odd Numbers
Step 1: Start
Step 2: Get N Value
Step 3: Set Initial Value I=1
Step 4: Check If(I<=N) Goto Step 5 Else Goto Step 8
Step 5: Print I Value
Step 6: Increment I Value By 2
Step 7: Goto Step 4
Step 8: Stop
Begin
Get N
Initialize I=1
While(I<=N) Do
Print I
I=I+2
Endwhile
End
30
Write An Algorithm To Print N Even Numbers
Step 1: Start
Step 2: Get N Value
Step 3: Set Initial Value I=2
Step 4: Check If(I<=N) Goto Step 5 Else Goto Step8
Step 5: Print I Value
Step 6: Increment I Value By 2
Step 7: Goto Step 4
Step 8: Stop
Psuedocode
Begin
Get N
Initialize I=2
While(I<=N) Do
Print I
I=I+2
Endwhile
End
31
Write An Algorithm To Print Squares Of A Number
Step 1: Start
Step 2: Get N Value
Step 3: Set Initial Value I=1
Step 4: Check I Value If(I<=N) Goto Step 5 Else Goto Step8
Step 5: Print I*I Value
Step 6: Increment I Value By 1
Step 7: Goto Step 4
Step 8: Stop
Psuedocode
Begin
Get N
Initialize I=1
While(I<=N) Do
Print I*I
I=I+2
Endwhile
End
32
Write An Algorithm To Print To Print Cubes Of A Number
Step 1: Start
Step 2: Get N Value
Step 3: Set Initial Value I=1
Step 4: Check I Value If(I<=N) Goto Step 5 Else Goto Step8
Step 5: Print I*I *I Value
Step 6: Increment I Value By 1
Step 7: Goto Step 4
Step 8: Stop
Begin
Get N
Initialize I=1
While(I<=N) Do
Print I*I*I
I=I+2
Endwhile
End
33
Write An Algorithm To Find Sum Of A Given Number
Step 1: Start
Step 2: Get N Value
Step 3: Set Initial Value I=1, Sum=0
Step 4: Check I Value If(I<=N) Goto Step 5 Else Goto Step8
Step 5: Calculate Sum=Sum+I
Step 6: Increment I Value By 1
Step 7: Goto Step 4
Step 8: Print Sum Value
Step 9: Stop
Begin
Get N
Initialize I=1,Sum=0
While(I<=N) Do
Sum=Sum+I
I=I+1
Endwhile
Print Sum
End
34
Write An Algorithm To Find Factorial Of A Given Number
Step 1: Start
Step 2: Get N Value
Step 3: Set Initial Value I=1, Fact=1
Step 4: Check I Value If(I<=N) Goto Step 5 Else Goto Step8
Step 5: Calculate Fact=Fact*I
Step 6: Increment I Value By 1
Step 7: Goto Step 4
Step 8: Print Fact Value
Step 9: Stop
Begin
Get N
Initialize I=1,Fact=1
While(I<=N) Do
Fact=Fact*I
I=I+1
Endwhile
Print Fact
End
35