C Program To Find Armstrong Number In Given Range (0-999)
Posted by
Bhushan hadkar
Labels:
Looping Programs
couch mode
print story
We have seen how to check if the given number is Armstrong number or not in c, now we have to find armstrong numbers in a range of numbers specified by the user.
To perform this program we have to get a number from the user, and run a loop from 1 to the number entered by the user.
And In this loop, we have to run the program to check the given number is armstrong number or not. And then if the number armstrong we have to print it on the screen.
C Program To Generate And Print Armstrong Numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,t,c,d,s=0;
clrscr();
printf("\n Enter the range from 0 to : ");
scanf("%d",&n);
printf("\n Armstrong Numbers are :");
for(i=0;i<=n;i++)
{
t=i;
s=0;
while(t!=0)
{
d=t%10;
c=d*d*d;
s=s+c;
t=t/10;
}
if(s==i)
printf(" %d",i);
}
getch();
}
Output :
In this way we can print armstrong numbers in a given range.