Armstrong Number
Write a program to print out all Armstrong numbers between 1 to 500.If sum of cubes of each digit of the number is equal to number itself,then the number is called an Armstrong number.For example,153={1*1*1}+{5*5*5}+{3*3*3}.
#include
#include
void main(void)
{
clrscr();
int dig1,dig2,dig3,num,temp;
num=001;
printf("Printing all the numbers form 1 to 500\n");
while(num<=500)
{
dig1=num-((num/10)*10);
dig2=(num/10)-((num/100)*10);
dig3=(num/100)-((num/1000)*10);
temp=(dig1*dig1*dig1)+(dig2*dig2*dig2)+(dig3*dig3*dig3);
if(num==temp)
{
printf("Armstrong Number:%d\n",num);
}
num++;}
getch();
}
#include
#include
void main(void)
{
clrscr();
int dig1,dig2,dig3,num,temp;
num=001;
printf("Printing all the numbers form 1 to 500\n");
while(num<=500)
{
dig1=num-((num/10)*10);
dig2=(num/10)-((num/100)*10);
dig3=(num/100)-((num/1000)*10);
temp=(dig1*dig1*dig1)+(dig2*dig2*dig2)+(dig3*dig3*dig3);
if(num==temp)
{
printf("Armstrong Number:%d\n",num);
}
num++;}
getch();
}
Comments
Post a Comment