/* 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;
}
#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;
}
No comments:
Post a Comment