/* Print Armstrong Numbers upto N */
#include<stdio.h>
int main()
{
int i,j,sum,n;
printf("Please enter the value of N: ");
scanf("%d",&n);
for(i=2;i<=500;i++)
{
for(j=i,sum=n;j>=1;j=j/10)
sum=sum+(j%10)*(j%10)*(j%10);
if(sum==i)
printf("%d is Armstrong.\n",i);
}
return 0;
}
Related Links:
Check Armstrong Number
http://cbasicprogram.blogspot.in/2012/05/check-armstrong-number.html
#include<stdio.h>
int main()
{
int i,j,sum,n;
printf("Please enter the value of N: ");
scanf("%d",&n);
for(i=2;i<=500;i++)
{
for(j=i,sum=n;j>=1;j=j/10)
sum=sum+(j%10)*(j%10)*(j%10);
if(sum==i)
printf("%d is Armstrong.\n",i);
}
return 0;
}
Related Links:
Check Armstrong Number
http://cbasicprogram.blogspot.in/2012/05/check-armstrong-number.html
why for(i=2;i<=500;i++) is used?
ReplyDeleteArmstrong program in C
ReplyDeleteNice post
it's not working
ReplyDeleteits not working and not getting the correct output
ReplyDeleteif you want to right answer then changed this code sum=0 instead of sum=n, and n instead of 500.
Deletenice article for beginners.thank you.
ReplyDeletewelookups C++
javacodegeeks
#include
ReplyDelete#include
int casg(int);
int main()
{
int j,i;
for(i=10;i<10000;i++)
{
j=casg(i);
if (j==1)
printf ("%d\n",i);
}
return 0;
}
int casg(int a)
{
int q,w,e=0,r,t,y,u,s=0,o;
r=a;
t=a;
while(a>0)
{
q=a%10;
a=a/10;
e++;
}
while(r>0)
{
y=r%10;
r=r/10;
s=s+pow(y,e);
}
if(s==t)
return 1;
else
return 0;
}