0% found this document useful (0 votes)
477 views10 pages

Chapter 02 Past Paper and Excercise Questions

An algorithm is a step-by-step method for solving a problem or completing a task. The document provides examples of algorithms, including an algorithm to check if a number is even or odd. It also discusses flowcharts, which use graphical symbols to represent the steps in an algorithm. Key flowchart symbols include terminals, inputs/outputs, processing boxes, decision diamonds, connectors, and flow lines. Examples are given of flowcharts for problems like inputting two numbers and finding the largest, and printing the multiplication table of a given number. Control structures like sequence, selection, and iteration are also summarized.

Uploaded by

sana mahmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
477 views10 pages

Chapter 02 Past Paper and Excercise Questions

An algorithm is a step-by-step method for solving a problem or completing a task. The document provides examples of algorithms, including an algorithm to check if a number is even or odd. It also discusses flowcharts, which use graphical symbols to represent the steps in an algorithm. Key flowchart symbols include terminals, inputs/outputs, processing boxes, decision diamonds, connectors, and flow lines. Examples are given of flowcharts for problems like inputting two numbers and finding the largest, and printing the multiplication table of a given number. Control structures like sequence, selection, and iteration are also summarized.

Uploaded by

sana mahmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Chapter#02

Past Paper and Exercise Questions:


Q1: What is an Algorithm? (2013)
An algorithm is a step by step method of solving a problem. It is commonly used for
data processing, calculation and other related computer and mathematical operations.
An algorithm is also used to manipulate data in various ways, such as inserting a new
data item, searching for a particular item or sorting an item.

Examples of Algorithm:
Algorithm to Check Even or Odd
Step 1: Start

Step 2: Read N

Step 3: Check: if N%2 == 0 Then

Step4: Display N is an Even Number.

Step5: Then display N is an Odd Number.

Step 4: Exit
Coding:

…. .

Q: Write different algorithm standard notations. (2013)


Book page number 25.
Q: Different examples of algorithms:
Write importance of an algorithm in computer programming? (2012)
Algorithms are very important in computer Science. The best-chosen algorithm
makes sure computer will do the given task at best possible manner. In cases
where efficiency matter a proper algorithm is vital to be used. An algorithm is
important in optimizing a computer program according to the available
resources. Ultimately when anyone decide to solve a problem through better
algorithms then searching for the best combination of program speed and least
amount of memory consumption is desired.
What is flowchart? Describe different symbols used while drawing a flowchart.
(2012)
What is a Flowchart?

Flowchart is a graphical representation of an algorithm. Programmers often use


it as a program-planning tool to solve a problem. It makes use of symbols which
are connected among them to indicate the flow of information and processing.
The process of drawing a flowchart for an algorithm is known as “flowcharting”.
Basic Symbols used in Flowchart Designs
1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic
flow. A pause/halt is generally used in a program logic under some error
conditions. Terminal is the first and last symbols in the flowchart.

2. Input/Output: A parallelogram denotes any function of input/output type.


Program instructions that take input from input devices and display output on
output devices are indicated with parallelogram in a flowchart.

3. Processing: A box represents arithmetic instructions. All arithmetic processes


such as adding, subtracting, multiplication and division are indicated by action
or process symbol.

4. Decision Diamond symbol represents a decision point. Decision based


operations such as yes/no question or true/false are indicated by diamond in
flowchart.

5. Connectors: Whenever flowchart becomes complex or it spreads over more


than one page, it is useful to use connectors to avoid any confusions. It is
represented by a circle.

6. Flow lines: Flow lines indicate the exact sequence in which instructions are
executed. Arrows represent the direction of flow of control and relationship
among different symbols of flowchart.
Examples of Flow Charts:
Draw a flowchart to input two numbers from user and display the largest of
two numbers

Coding:
void main()
{
int num1, num2, largest;

/*Input two numbers*/


printf("Enter two numbers:\n");
scanf("%d%d", &num1, &num2);

/*check if a is greater than b*/


if (num1 > num2)
printf(“number 1 is largest”);
else
printf(“number 2 is largest”);
/*Print the largest number*/
printf("%d", largest);

getch();
}

Input 2 numbers from user and print their sum

Draw a flowchart that prints the table of any inputted number.


(2016)
An algorithm gives step by step instructions on how to solve a
problem.
Step 1: Start /*start the process*/
Step 2: Input n /*the number for which multiplication table is to be printed*/
Step 3: Input c=1
Step 4: Print m = n*c
Step 5: End
Q: What is meant by control structure?
In a program, control structures control how the program executes. Algorithms,
flowcharts and their equivalent computer programs are more easily understood
if they mainly use self-contained modules and three types of logic, or flow of
control, called
1) Sequence logic, or sequential flow
2) Selection logic, or conditional flow
3) Iteration logic, or repetitive flow
1) Sequence logic, or sequential flow

Sequence control structure” refers to the line-by-line execution by which statements are
executed sequentially, in the same order in which they appear in the program. They might,
for example, carry out a series of read or write operations, arithmetic operations, or
assignments to variables.
Example:

1) Selection logic, or conditional flow

The selection structure tests a condition, then executes one sequence of statements instead
of another, depending on whether the condition is true or false. A condition is any variable or
expression that returns a Boolean value (TRUE or FALSE).
1) Iteration logic, or repetitive flow

Iteration The iterative control structures are used for repetitively executing a block of code
multiple times; the following are the basic iterative control structures.
for: A for loop execute the statements for a specific number of times mentioned in the
while: A while loop executes statement repeatedly until the condition satisfies.
do-while: A do-while loop works like while loop, the only difference is it executes the
statement once before checking the condition

Flowchart of while Loop


for loop Flowchart

Flowchart of do...while Loop

You might also like