Advertisement Remove all ads

P Define Algorithm. Write Algorithm to Check Whether Given Number is Armstrong Number Or Not Also Mention Input and Output Specifications to Algorithm. - Structured Programming Approach

Define Algorithm. Write Algorithm to check whether given number is Armstrong number or not also mention input and output specifications to algorithm. 

Advertisement Remove all ads


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 lgorithm 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.
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.”
Print “Number n is not an Armstrong number.”
Step X : Stop

  Is there an error in this question or solution?
Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads

View all notifications

      Forgot password?
View in app×