Function to check whether the given number is Armstrong number or not * Function to calculate order of the number */ If they are equal, it’s an Armstrong number. When the last digit is removed from N, it is divided by 10. Then the result is computed by cubing a or using Math. With every iteration, the last digit of N is stored in a. A while loop is used to lop through the number N until it is equal to 0. This is done as we need to compare the values of the original number and the final number at the end. (“Not Armstrong number”) įirst, a given number N’s value is stored in another integer variable, x. Int n=153 //It is the number to check Armstrong If sum != X, print not Armstrong number Program to Check Armstrong Number in Java To understand this program, we need knowledge of the following topics in Java: For this, we will be using a while loop and for loop in Java. In this article, we will learn to check whether an input number is an Armstrong number or not.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |