Program to generate armstrong numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, a, r, s, n;
clrscr() ;
printf("Enter the limit : ");
scanf("%d", &n);
printf("\nThe armstrong numbers are :\n\n");
for(i = 0; i <= n; i++)
{
a = i;
s = 0;
while(a > 0)
{
r = a % 10;
s = s + (r * r * r);
a = a / 10;
}
if(i == s)
printf("%d\t", i);
}
getch();
}
Output:
Enter the limit : 1000
The armstrong numbers are :
0 1 153 370 371 407
-
UpdatedDec 31, 2019
-
Views4,940
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order