/ Undifined / 19 - WAP to print Armstrong numbers from 1 to 100.

19 - WAP to print Armstrong numbers from 1 to 100.

WAP to print Armstrong numbers from 1 to 100. 
#include <stdio.h>
 
main()
{
int number, temp, digit1, digit2, digit3;
 
printf("Print all Armstrong numbers between 1 and 1000:\n");
number = 001;
while (number <= 900)
{
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++;
}
}
Output 
Print all Armstrong numbers between 1 and 1000:
 
Amstrong no is:1
Amstrong no is:153
Amstrong no is:370
Amstrong no is:371
Amstrong no is:407

about author

Blogger Sens it website about blogger templates and blogger widgets you can find us on social media
Previous Post :Go to tne previous Post
Next Post:Go to tne Next Post

No comments:

Post a Comment