Users Online

· Guests Online: 149

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

36 C Program to Print Armstrong Number from 1 to 1000

This C Program print armstrong number from 1 to 1000. An Armstrong number is an n-digit base b number such that the sum of its (base b) digits raised to the power n is the number itself. Hence 153 because 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.
Here is source code of the C Program to print armstrong number from 1 to 1000.
The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Print Armstrong Number from 1 to 1000
*/
#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:
$ cc pgm44.c
$ a.out
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

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.01 seconds
10,814,209 unique visits