Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = (1*1*1) + (5*5*5) + (3*3*3)

#include<stdio.h>
main()
{
int number, temp, digit1, digit2, digit3;

printf("Printing all Armstrong numbers between 1 and 500:\n\n");

number = 001;

while (number <= 500)
{
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("\nAmstrong Number:%d", temp);

}

number++;
}
}



The file can be found at:
Download File.

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin