1
4.2kviews
Define algorithm. Write Algorithm to check whether given number is Armstrong Number or not also mention input and output specification to algorithm.

Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 10M

Year: Dec 2018

1 Answer
2
350views

Algorithm:

An Algorithm is a sequence of steps to solve a problem.Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.

Characteristics of Algorithm:

1) Finiteness- An algorithm must always terminate after a finite number of steps.

2) Definiteness- Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case.

3 )Input- An algorithm has zero or more inputs, i.e, quantities which are given to it initially before the algorithm begins.

4) Output- An algorithm has one or more outputs i.e, quantities which have a specified relation to the inputs.

5) Effectiveness- An algorithm is also generally expected to be effective. This means that all of the operations to be performed in the algorithm must be sufficiently basic that they can in principle be done exactly and in a finite length of time.

Algorithm to check whether given number is Armstrong or not:

Step I: Start.

Step II: Input n, sum, rem, temp.

Step III: sum = 0, rem=0.

Step IV: Print “Enter an integer number : ”

Step V: Read n.

Step VI: temp = n.

Step VII: If temp is less than equal to zero Then,

Go to Step IX.

Else

rem = temp mod 10

sum = sum + ( rem X rem X rem )

temp = temp / 10

Step VIII: Go to Step VII.

Step IX: If sum is equal to n Then,

Print “Number n is an Armstrong number.”

Else

Print “Number n is not an Armstrong number.”

Step X: Stop

Please log in to add an answer.