12. Find the amstrong
numbers within a given
range.
#include
<stdio.h>
main()
{
int ll,ul,number, temp, digit1, digit2,
digit3;
clrscr();
printf("Enter number range\n");
printf("Enter lower limit\n");
scanf("%d",&ll);
printf("Enter upper limit\n");
scanf("%d",&ul);
printf("Print all Armstrong numbers
between %d and %d:\n",ll,ul);
number = ll;
while (number <= ul)
{
digit1 = number - ((number / 10) * 10);
digit2 = (number / 10) - ((number /
100) * 10);
digit3 = (number / 100) - ((number /
1000) * 10);
temp = (digit1 * digit1 * digit1) +
(digit2 * digit2 * digit2) + (digit3 * digit3 * digit3);
if (temp == number)
{
printf("\n Armstrong no
is:%d", temp);
}
number++;
}
getch();
}
No comments:
Post a Comment