Sequence means that each step or process in the algorithm is executed in the specified order.In the Kettle example,each process must be in the proper place otherwise the algorithm will fail.

###

####

####

####
IF YOU NEED ANY MORE INFORMATION RELATED TO ALGORITHM,VISIT THIS LINK:

###
__The decision constructs -if...then,if...then...else...__

In algorithms the outcome of a decision is either true or false;there is no state in between.The outcome of the decision is based on some condition that can only result in a true or false value.

**For example:**

*if today is Monday then collect pay*

Here,the above statement is a decision and the decision takes the general form:

__if proposition then process__
A proposition,in this sense,is a statement,which can only be true or false.It is either true that 'today is Monday' or it is false.If the proposition is true,then the process or procedure that follows the proposition is executed.

__The decision can also be stated as:__**if proposition**

*then process 1***else**

*process 2*
This is the if...then...else... form of decision.This means that if the proposition is true,then execute process 1,else execute process 2.

The first form of the decision if proposition then process has a null else,that is,there is no else.

####
__Let us take an example to understand sequence and decision.__

__Let us take an example to understand sequence and decision.__

__Q1)Write an algorithm to check whether a number given by user is even or odd.__**Solution:**Let the number to be checked be represented by 'N'.

The number 'N' is divided by 2 to give an integer quotient,denoted by Q.If the remainder,designated as 'R' is zero,'N' is even,otherwise 'N' is odd.This logic is applied in following algorithm.

- START
- [Ask Input]

Print "Enter the number" - [Take Input]

Input N - [Logic Applied to find whether number is even or odd]

Q <- N/2 (i.e. Q=N/2) - [Finding remainder]

R <- N-Q*2 (i.e. R=N-Q*2) - [Decision Construct]

If R = 0 then Print "N is EVEN" - [Decision Construct] If R!=0 then Print "N is ODD"
- STOP

__Q2)Print the largest among three numbers.__**Solution:**Let the three number be represented by A,B, and C.There can be three ways of solving the problem.The three algorithms with some differences are given below:

*By using*

**Type 1:****AND operator.**

- START
- Print "Enter the Number"
- Input A,B,C
- If A >= B AND B>=C

Then print A - If B >= C AND C >= A

Then Print B

ELSE Print C - STOP

*This algorithm uses a*

**Type 2:****variable MAX**to

**store**the

**largest number**.

- START
- Print "Enter THREE NUMBERS"
- Input A,B,c
- MAX <-A (i.e. MAX=A)
- If B > MAX Then MAX <- B (i.e. MAX=B)
- If C > MAX Then MAX <- C (i.e. MAX=C)
- Print MAX
- STOP

*Type 3:*This algorithm

**uses a nested if construct.**

- START
- Print "Enter three number"
- Input A,B,C
- If A > B then

If A > C Then

Print AElse Print C

Else If B > C Then

Print B

Else Print C - STOP

####
__NOTE:__More examples of ALGORITHM will be updated only on user demand.

####
IF YOU NEED ANY MORE INFORMATION RELATED TO ALGORITHM,VISIT THIS LINK: __HTTP://GOO.GL/YLJXYP__

__HTTP://GOO.GL/YLJXYP__

*Please don't forget to share this information with your friends.*
## 0 comments:

Post a Comment