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.

  1. /*
  2.  * C Program to Print Armstrong Number from 1 to 1000
  3.  */
  4. #include <stdio.h>
  5.  
  6. main()
  7. {
  8.     int number, temp, digit1, digit2, digit3;
  9.  
  10.     printf("Print all Armstrong numbers between 1 and 1000:\n");
  11.     number = 001;
  12.     while (number <= 900)
  13.     {
  14.         digit1 = number - ((number / 10) * 10);
  15.         digit2 = (number / 10) - ((number / 100) * 10);
  16.         digit3 = (number / 100) - ((number / 1000) * 10);
  17.         temp = (digit1 * digit1 * digit1) + (digit2 * digit2 * digit2) + (digit3 * digit3 * digit3);
  18.         if (temp == number)
  19.         {
  20.             printf("\n Armstrong no is:%d", temp);
  21.         }
  22.         number++;
  23.     }
  24. }


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

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.

If you liked this C Program, kindly share, recommend or like below!

About

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.


Sanfoundry Training Center of Excellence (CoE)

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.







Subscribe Newsletter & Posts
Sanfoundry Internships
Follow Manish & Sanfoundry