armstrong

Solutions on MaxInterview for armstrong by the best coders in the world

showing results for - "armstrong"
Valery
02 Nov 2016
1//examples = 370;371;153;407;
2// made by Kashish Vaid the great
3#include <stdio.h>
4#include <math.h>
5void main()
6{
7int i, num, result=0, remainder;
8// applicable for 3 digits only 
9printf("Enter 3 digit number: ");
10scanf("%d",&num);
11
12for( i=num ; i != 0 ; i/=10)
13		{ 
14  		remainder = i % 10;
15		result += remainder * remainder * remainder;
16        }
17    // if else shortcut
18    ( (result == num) ? printf("%d is an Armstrong no.",num) : printf("%d isn't an Armstrong no.",num) );
19}
20// made by Kashish Vaid the great 
Giacomo
09 Mar 2018
1public class Armstrong {
2
3    public static void main(String[] args) {
4
5        int number = 1634, originalNumber, remainder, result = 0, n = 0;
6
7        originalNumber = number;
8
9        for (;originalNumber != 0; originalNumber /= 10, ++n);
10
11        originalNumber = number;
12
13        for (;originalNumber != 0; originalNumber /= 10)
14        {
15            remainder = originalNumber % 10;
16            result += Math.pow(remainder, n);
17        }
18
19        if(result == number)
20            System.out.println(number + " is an Armstrong number.");
21        else
22            System.out.println(number + " is not an Armstrong number.");
23    }
24}
similar questions
queries leading to this page
armstrong