Computer Science, asked by esv, 1 year ago

write a program using for next loop statement to find the armstrong number between 1 to 500 (153 is Armstrong number )

Answers

Answered by Anonymous
2

CODE :


class armstrong

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int c=0;

int d=0;

double s=0;

int dn=0;

for(int i=1;i<=500)

{

int cpy=i;

int c=i;

while(cpy>0)

{

dn++;

cpy=cpy/10;

}

while(c>0)

{

d=c%10;

s=s+Math.pow(d,dn);

dn--;

c=c/10;

}

if(s==i)

System.out.println("Armstrong number="+i);

}

}

}

_________________________

NOTE :

⇒ First proceed by finding the number of digits in the the value of i.

⇒ Then find the armstrong number using the logic implemented above ↑↑↑↑↑

⇒ Compile in Blue J or any other compilers.

⇒ U may or may not use static in main !


Hope it helps !


______________________________________________

Similar questions