WRITE A C PROGRAM TO PRINT ALL ARMSTRONG NUMBERS BETWEEN 1 AND 500
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,c,n,a,x;
printf("The Armstrong numbers between 1 and 500 are: ");
for(i=1;i<=500;i++)
{
c=0;
x=0;
n=i;
while(n!=0)
{
n=n/10;
c++;
}
n=i;
while(n!=0)
{
a=n%10;
n=n/10;
x=x+pow(a,c);
}
if(i==x)
printf("%d ",i);
}
}
getch();
}
Output:
The Armstrong numbers between 1 and 500 are: 1 2 3 4 5 6 7 8 9 153 370 371 407
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,c,n,a,x;
printf("The Armstrong numbers between 1 and 500 are: ");
for(i=1;i<=500;i++)
{
c=0;
x=0;
n=i;
while(n!=0)
{
n=n/10;
c++;
}
n=i;
while(n!=0)
{
a=n%10;
n=n/10;
x=x+pow(a,c);
}
if(i==x)
printf("%d ",i);
}
}
getch();
}
Output:
The Armstrong numbers between 1 and 500 are: 1 2 3 4 5 6 7 8 9 153 370 371 407
,2,3,4,,5,6,7,8,9 armstrong num nhi haen bhayiiiii
ReplyDeletebrother plz remove 1st while loop as it is unnecessary.b'coz in armstrong no.s,we take cube of all the digits.not power of digit count .and add 3 in power function in d place of c (like pow(a,3)).
ReplyDelete1,153,370,371,407 are the armstrong no in the given range.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteArmstrong program in C
ReplyDeletenice
A number is called an Armstrong number if the sum of cubes of every digit is equal to the number itself. Here is the armstrong number check program
ReplyDelete