Source Code
// 26. Program to display Armstrong numbers between two intervals
// Arpan Das - CST 2nd Year (VOCLET)
// 153 = (1^3) + (5^3) + (3^3)
#include <stdio.h>
//#include <conio.h>
#include <math.h>
void main () {
int num, num2, num3, temp, digits, start, end, i;
//system("cls");
//clrscr();
printf("\t\t..:: check whether a number is amstrong or not ::..\n\n");
printf("pleae enter starting and ending range respectively: ");
scanf("%d%d", &start, &end);
for (i = start; i<= end; i++) {
num = num2 = num3 = i;
digits = 0;
while (num3 != 0) {
num3 /= 10;
digits++;
}
temp = 0;
while (num2 != 0) {
//temp += pow(num2%10, digits);
temp += (int)(pow(num2%10, digits) + 0.5);
num2 /= 10;
}
if (temp == num)
printf("\n%d is an amstrong number.", num);
}
//getch();
}
Output
..:: check whether a number is amstrong or not ::..
pleae enter starting and ending range respectively: 1 1000
1 is an amstrong number.
2 is an amstrong number.
3 is an amstrong number.
4 is an amstrong number.
5 is an amstrong number.
6 is an amstrong number.
7 is an amstrong number.
8 is an amstrong number.
9 is an amstrong number.
153 is an amstrong number.
370 is an amstrong number.
371 is an amstrong number.
407 is an amstrong number.