Pseudocode and Algorithm to find whether number is Armstrong Number or Not

(5375 Views)


What is an Armstrong number?

An Integer number in which the sum of the cubes of its digits is equal to the number itself is called Armstrong Number. For example, 153 is an Armstrong number since 1**3 + 5**3 + 3**3 = 153.

Pseudocode and Algorithm for Armstrong Number

Algorithm to find whether number is Armstrong Number or Not

Step 1: Start Step 2: Declare Variable sum, temp, num Step 3: Read num from User Step 4: Initialize Variable sum=0 and temp=num Step 5: Repeat Until num>=0 5.1 sum=sum + cube of last digit i.e [(num%10)*(num%10)*(num%10)] 5.2 num=num/10 Step 6: IF sum==temp Print "Armstrong Number" ELSE Print "Not Armstrong Number" Step 7: Stop

Pseudocode to find whether number is Armstrong Number or Not

READ n temp=n sum=0 WHILE n>=0 sum=sum+(n%10)*(n%10)*(n%10) n=n/10 ENDWHILE IF sum==temp WRITE "NUMBER IS AN ARMSTRONG NUMBER" ELSE WRITE "NUMBER IS NOT AN ARMSTRONG NUMBER"

We first take input from user and store it in variable n. Then we initialize 2 variables temp to n and sum to 0. We calculate the cube of last digit by this expression [(n%10)*(n%10)*(n%10)] and add it to value of sum and also divide n by 10. We repeat the above step until n is greater than or equal to 0. At last, we check whether sum is equal to temp, if yes Print "Number is Armstrong Number" else print "Number is Not Armstrong Number".

Flowchart For Armstrong Number

Flowchart for Armstrong Number
        

Solution Didn't Worked 9 DownvotesDownvote



Comments



Search