English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

A number is said to be an Armstrong number if the sum of the cubes of all
of its digits equals its value. Write a pseudo-code that given number N tells if it is
Armstrong or not. For example 153 is an Armstrong number: 13 + 53 + 33 = 153

2007-10-25 21:41:38 · 2 answers · asked by zilla_mafia 2 in Science & Mathematics Mathematics

2 answers

Armstrong number is a number that in a given base is the sum of its own digits to the power of the number of digits.

u made a mistake... u said cubes... but i didn't write them in the example...

it should be 1^3 + 5^3 + 3^3 = 153..

furthermore..... i don't have the slightest understanding of programming..:)))))

2007-10-25 21:49:34 · answer #1 · answered by Matei Stefan 5 · 0 1

Here's actual java code that finds all four Armstrong numbers from 100 to 1000 in about the time of a heartbeat. One thing about pseudo-code, you can't run it to see what it will actually do. Following is the main method followed by the output.

public static void main( String[] args ) {
System.out.println("Hello Zilla");
for(int C = 1; C < 10; C++){
for(int X = 0; X < 10; X++){
for(int I = 0; I < 10; I++){
if(C*C*C + X*X*X +I*I*I == C*100 + X*10 + I){
System.out.println((C*100 + X*10 + I) + " is Armstrong");
}
}
}
}
}//CLOSE MAIN

OUTPUT:
Hello Zilla
153 is Armstrong
370 is Armstrong
371 is Armstrong
407 is Armstrong

2007-10-26 02:47:32 · answer #2 · answered by jsardi56 7 · 0 0

fedest.com, questions and answers