#include(conio.h)
int main( )
{
int no, temp, rem, sum;
clrscr( );
printf("Armstrong numbers between 1 and 1000 are:\n");
for(no=1; no<=1000; no++)
{
temp=no;
sum=0;
while(temp>0)
{
rem=temp%10;
sum=sum+(rem*rem*rem);
temp=temp/10;
}
if(no==sum)
printf("\n%d", no);
}
getch( );
return 0;
}
Output:
Armstrong numbers between 1 and 1000 are:
1
153
370
371
407
2,3,4,5,6,7,8,9 are also armstrong numbers
ReplyDeleteNo if we cube 2 we get 8 and 8=2 so 2 is not armstrong no and all these no are not armstrong no except 1.
Deleteare madam ki madam se padh ki aayi ho...
Deletey cant 2,3,4,5,6,7,8,9 be an armstrong numbers
ReplyDeletewhy temp variable used in armstong number
ReplyDeletewaste,1 is armstrong,and program can be compiled using two while loops
ReplyDeletearmstrong number means cube of all digits.
ReplyDeleteex: 153
1^3 + 5^3 + 3^3
1+125+27=153
it is not proper program to understand and write it well and post the correct program to me at nanduk371@gmail.com
ReplyDeleteit should be
ReplyDeleteif(sum==temp)
printf("%d\n",temp);
thanx a lot for ua support sir!!! ths site is realy vry help ful for me as m pursuing mah B.Tech...... i was in search of this kinda site 4m many days!!!
ReplyDeletearmstrong number
ReplyDeleteexample:
1) ab=(a*a)+(b*b)
2) abc=(a*a*a)+(b*b*b)+(c*c*c)
3) abcd=(a*a*a*a)+(b*b*b*b)+(c*c*c*c)+(d*d*d*d)
and so on
so the above program is wrong if there exist a two digit armstrong number
ReplyDeleteHow do you personally browse for info for your fresh posts, which particular search networks do you often rely on?
ReplyDeletecan any one tell why my below program prints all Armstrong except 153??
ReplyDelete#include
#include
int main()
{
int num,a,c=0,d,e,f,g,min,max,sum=0;
printf("Enter a min and max\n");
scanf("%d %d",&min,&max);
num=min;
while(num<=max)
{ a=num;
d=a;
c=0;
sum=0;
while(a!=0)
{
c++;
a=a/10;
}
while(d!=0)
{ g=d%10;
f=pow(g,c);
sum=sum+f;
d=d/10;
}
if(sum==num)
{
printf("\n armstrog=%d\n",num);
}
num++;
}
return 0;
}
According to definition 1,2,3,4,5,6,7,8,9 should be Armstrong numbers. Are they?
ReplyDeleteI think this program can help you better http://www.compprog.com/2014/02/write-program-to-find-first-1000.html
ReplyDeleteThank you. nice post... very usefull...
ReplyDelete