In this program, you'll learn to check whether a given number is armstrong number or not. You'll learn to do this by using a while loop in Kotlin.
In this program, we will read an integer number and check number is Armstrong or not, and print an appropriate message on the console screen. Program/Source Code: The source code tofind the given number is Armstrong or not using theforloopis given below. The given program is compiled and...
num = number # define a method for checking number is Armstrong or not def isArmstrong(self) : # copy num attribute to the temp variable temp = self.num res = 0 # run the loop untill temp is not equal to zero while(temp != 0) : rem = temp % 10 res += rem ** 3 # ...
Below is the procedure for armstrong number in C temp = num rem = 0 WHILE temp IS NOT 0 rem ← temp modulo 10 sum ← sum + power(rem, digits); divide temp by 10 END WHILE IF sum equivalent to num PRINT Armstrong Number ELSE PRINT not an Armstrong Number END IF end procedure C P...
Total number of digits get stored in a Repeat the loop till var > 0 Store the output of while loop in sum Check whether the user number is equal to sum or not If it is equal than print “It is an Armstrong number” Else print “It is not an Armstrong number” ...
In the above program, an Armstrong number of n digits is checked. When the user enters a number, it is taken as a string. The length property returns the length of a string. The number entered by the user is stored in a temp variable. And a while loop is used to iterate until its...
// while loop for manipulating the number while (number) { // remain contains the last element of the number remain = number % 10; // result contains the cube of remain added to it result = result + (remain * remain * remain); // number is divided by 10 at each iteration // ...