Wednesday, 23 April 2014

5. Write a program to find all Armstrong number in the range of 0 and 999 Hint: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits i!.’ equal to the number itself For example. 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371



#include<stdio.h>
#include<conio.h>
#include<math.h> void main()
{
int num,i,k,r,sum;
clrscr();
printf("Finding AMSTRONG no. range 0 -999\n");
for(i=1; i<=999; i++)
{
k=i;  
sum=0;
while(k != 0)
{
r=k%10;
sum=sum+pow(r,3);
k=k/10;
}
if(i==sum)
Printf("%d is amstrong number\n",i);
}

getch();

}

No comments:

Post a Comment