Friday, 11 December 2020

Armstrong numbers from 1 to 1000

public class Armstrong1to1000 {
	public static void main(String[] args) {
		System.out.println("Amstrong Numbers From 1 to 1000");
		int a,r;
		for(int i=1; i<=1000;i++)
		{
			a=0;
			int n=i;
			while(n!=0) 
			{
				r=n%10;
				a=a+r*r*r;
				n=n/10;
			}
			if(a==i)
			{
				System.out.println(i);
			}
		}
	}
}

OUTPUT:

Amstrong Numbers From 1 to 1000
1
153
370
371
407

1 comment:

If you have any doubts, please let me know

Pattern 31 & 32