Armstrong numbers Program in C

Armstrong numbers Program in C
Armstrong numbers Program in C

WAP to print Armstrong numbers from 1 to 1000.

A positive number is called armstrong number if it is equal to the sum of cubes of its digits.

Examples: 153 is Armstrong

(1*1*1)+(5*5*5)+(3*3*3) = 153

#include<stdio.h>
void main()
{
	int i=1,r,aNum=0,num;
	for(i=1;i<=1000;i++)
	{
		num=i;
		aNum=0;
		while(num>0)
		{
			r=num%10;
			aNum=aNum+r*r*r;
			num=num/10;	
		}
		if(i==aNum)
		{
			printf("Armstrong Number=%d\n",i);	
		}			
	}	
}

Output:

Armstrong Number=1
Armstrong Number=153
Armstrong Number=370
Armstrong Number=371
Armstrong Number=407
b. tech. bca c language tutorial learn c language mca study c language
Recent Posts