Program to find all Armstrong numbers between 0 and 999

An Armstrong number of three digit is a number such that that sum of the cubes of it's digits is equal to the number itself For example 153 is an Armstrong number because cube of 1 is 1(1x1x1=1) + cube of 5 is 125(5*5*5=125) + cube of 3 is 27(3*3*3=27). Now add all the cubes 1+125+27=153 which is equals to number itself

1 /*Programme to find Armstrong number in the range of 0 and 999*/
2 #include <stdio.h>
3 #include <conio.h>
4 void main()
5 {
6 int num,rem,qub,sum=0,i;
7 printf("Armstrong numbers between 0 to 999 are: ");
8
9 for(i=0; i<=999; i++)
10 {
11 num=i;
12 sum=0;
13 while(num>0)
14 {
15 rem=num%10;
16 qub=rem*rem*rem;
17 sum=sum+qub;
18 num=num/10;
19 }
20 if(sum==i)
21 {
22 printf("%d,",sum);
23 }
24 }
25 getch();
26 }
27
28 http://www.sachinpuri.com/Article/61/what_is_an_armstrong_number.html
Add Your Comment
   
    Yes! I want to receive all comments by email

  by ammu on 19-Nov-2013 03:56 pm
its tooooo bad
  • Reply
  •  0 Like
  •  3 Dislike
  • Report
  by nakshatra on 19-Nov-2013 03:55 pm
thank uuuuuuuuuuu
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by IGNOU Student on 14-Sep-2013 11:11 pm
Thanks for the help, These algorithms are very useful for IGNOU MCA students
  • Reply
  •  12 Like
  •  0 Dislike
  • Report
  by ragul on 04-Jul-2013 03:58 pm
thank you
  • Reply
  •  8 Like
  •  0 Dislike
  • Report
  by ragul on 04-Jul-2013 03:57 pm
thank u
  • Reply
  •  5 Like
  •  0 Dislike
  • Report
  by garima moradia on 22-Apr-2013 12:31 pm
thank u .... :)
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by Sanjana Desai on 13-Mar-2013 09:21 pm
its easy:)
  • Reply
  •  5 Like
  •  1 Dislike
  • Report
  by umar mustapha on 26-Sep-2012 11:59 am
Write a C program that will accept 5 integers and display the lowest integer
  • Reply
  •  0 Like
  •  1 Dislike
  • Report
  by Sachin Puri on 26-Sep-2012 11:41 pm
http://www.sachinpuri.com/forum_posts.php?fid=271
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by umar mustapha on 26-Sep-2012 11:58 am
Type your comment...Write a C program that will accept 5 integers and display the lowest integer
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by java67 on 31-Aug-2012 08:03 am
Here is my way of finding Armstrong number in java
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by Santhosh on 07-Jun-2012 07:43 am
2 is an Armstrong number and how this program works for 2 through 9??2=2^3??
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by Sachin Puri on 07-Jun-2012 10:52 pm
This program is only for 3 digit armstrong numbers. Please see this updated one for all the numbers. http://www.sachinpuri.com/Algorithm/15/program_to_find_all_armstrong_numbers_(php).html
  • Reply
  •  14 Like
  •  1 Dislike
  • Report
  by anukul on 25-May-2012 11:02 pm
i love your programming techniques
  • Reply
  •  2 Like
  •  2 Dislike
  • Report
  by Sachin Puri on 27-May-2012 12:15 am
Thanks bro
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by kamlesh on 03-Apr-2012 07:51 am
this is my prog
  • Reply
  •  1 Like
  •  3 Dislike
  • Report
  by Sachin Puri on 03-Apr-2012 12:27 pm
What do you mean by saying this?
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by jesna on 22-Mar-2012 10:28 am
This one is the right program. Thanks for sharing Sachin!
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by Sachin agnihotri on 03-Jan-2012 09:21 pm
Tell me the program to find all armstrong number whether it is 4 digit or 5 digit
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by Sachin Puri on 04-Jan-2012 02:07 pm
Hi Sachin, Please see this link, i am writing this program in PHP, logic is same. http://www.sachinpuri.com/Algorithm/15/program_to_find_all_armstrong_numbers_(php).html
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by Shibani on 31-Oct-2012 10:43 am
can strlen be used on int values ? aren't they confined to strings ?
  • Reply
  •  1 Like
  •  0 Dislike
  • Report
  by Manish on 31-Oct-2012 01:40 pm
yes in php we can use strlen on int, php is smart enough to convert int in string to calculate length.
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by Brijesh on 28-Dec-2011 01:19 pm
This is right program....
  • Reply
  •  4 Like
  •  1 Dislike
  • Report
  by viv on 13-Oct-2011 03:16 pm
thanx buddy...
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by Ruchita on 14-Aug-2011 03:10 pm
Wat abt 1digit,2 digit armstrng number??can u help me with it?
  • Reply
  •  2 Like
  •  2 Dislike
  • Report
  by Sachin Puri on 16-Aug-2011 01:45 pm
An Armstrong number is an n digit number, which is equal to the sum of the nth powers of its digits. All the 1 digit numbers (1-9) are Armstrong number because 1*1=1 which is equals to number (1) itself, 2*1=2 which is equals to number(2) itself so on for all the 1 digit numbers (1-9).There are no 2 digit Armstrong numbers. Feel free to ask me if you still have doubt.
  • Reply
  •  4 Like
  •  14 Dislike
  • Report
  by Rajender Singh on 02-Sep-2012 04:03 pm
hello sachin,could you give me the program of the armstrong number for the above definition
  • Reply
  •  1 Like
  •  0 Dislike
  • Report
  by shraddha shikerkar on 02-Nov-2010 08:44 am
can u pls explain me wt is armstrong no an how the above program works? with d simplest example.
  • Reply
  •  2 Like
  •  2 Dislike
  • Report
  by Sachin Puri on 01-Apr-2011 09:34 pm
Example is given in intro. Example :- 153 contains three digits 1,5,3 the cube of 1 is 1 because 1x1x1=1, and cube of 5 is 125 because 5x5x5=125 and cube of 3 is 27 because 3x3x3=27 now add all the cubes 1 125 27=153 which is equals to number itself
  • Reply
  •  76 Like
  •  104 Dislike
  • Report
  by Sachin Puri on 08-Nov-2010 04:27 pm
To run this program simply copy paste it in notepad and save it "armstrong.c" now compile it with any C compiler like TC (Turbo C) and then run the program
  • Reply
  •  5 Like
  •  13 Dislike
  • Report