Facebook
Banner
XMPP JavaScript Library READ MORE

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 #include <stdio.h>
2 #include <conio.h>
3 #include <strings.h>
4 #include <math.h>
5
6 int noOfDigits(int n){
7 unsigned int number_of_digits = 0;
8
9 do {
10 ++number_of_digits;
11 n /= 10;
12 } while (n);
13
14 return number_of_digits;
15 }
16
17
18 int main()
19 {
20 int num,rem,qub,sum=0,i,len;
21 printf("Armstrong numbers between 0 to 999 are: ");
22
23 for(i=0; i<=999; i++)
24 {
25 num=i;
26 sum=0;
27 len=noOfDigits(i);
28 while(num>0)
29 {
30 rem=num%10;
31 qub=pow(rem,len);
32 sum=sum+qub;
33 num=num/10;
34 }
35 if(sum==i)
36 {
37 printf("%d,",sum);
38 }
39 }
40 getch();
41 }
42
43 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 Vish Ya Amrit Sitara on 14-Mar-2019 02:16 pm
This is energizing, in any case it is imperative for you to visit this particular url:
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by fathima on 20-Sep-2015 09:00 pm
How to write this in java?
  • Reply
  •  2 Like
  •  5 Dislike
  • Report
  by Phponwebsites on 28-Aug-2015 06:10 pm
Thank you very much..
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by jisha varghese on 21-Mar-2015 08:47 am
thanks for this program
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by karthik on 07-Feb-2015 01:35 pm
mr.author infact 1,2,3,4,5,6,7,8,9 is also an armstrong number but your program doesnt display those so plz do the necessary
  • Reply
  •  2 Like
  •  1 Dislike
  • Report
  by aakash on 28-Dec-2014 04:34 pm
Thks for this program
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by sagar on 17-Dec-2014 04:12 pm
what is rem and qub.
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by elakkiya.m on 28-Sep-2014 02:23 pm
nice idea,good luck for creating new ideas
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by NamevishnĂș on 26-Sep-2014 09:00 pm
Type your comment...I. not. I. programing friendzzzz. so. pllzz. tell. programing and problem solving apidi. padikarathunuu. programing gaaa. varamatikuthuuu
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by ammu on 19-Nov-2013 03:56 pm
its tooooo bad
  • Reply
  •  1 Like
  •  4 Dislike
  • Report
  by nakshatra on 19-Nov-2013 03:55 pm
thank uuuuuuuuuuu
  • Reply
  •  1 Like
  •  1 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
  •  14 Like
  •  1 Dislike
  • Report
  by ragul on 04-Jul-2013 03:58 pm
thank you
  • Reply
  •  9 Like
  •  1 Dislike
  • Report
  by ragul on 04-Jul-2013 03:57 pm
thank u
  • Reply
  •  6 Like
  •  1 Dislike
  • Report
  by garima moradia on 22-Apr-2013 12:31 pm
thank u .... :)
  • Reply
  •  3 Like
  •  2 Dislike
  • Report
  by Sanjana Desai on 13-Mar-2013 09:21 pm
its easy:)
  • Reply
  •  6 Like
  •  2 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
  •  1 Like
  •  2 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
  •  1 Like
  •  1 Dislike
  • Report
  by java67 on 31-Aug-2012 08:03 am
Here is my way of finding Armstrong number in java
  • Reply
  •  1 Like
  •  1 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
  •  6 Like
  •  3 Dislike
  • Report
  by anukul on 25-May-2012 11:02 pm
i love your programming techniques
  • Reply
  •  3 Like
  •  3 Dislike
  • Report
  by Sachin Puri on 27-May-2012 12:15 am
Thanks bro
  • Reply
  •  2 Like
  •  2 Dislike
  • Report
  by kamlesh on 03-Apr-2012 07:51 am
this is my prog
  • Reply
  •  2 Like
  •  4 Dislike
  • Report
  by Sachin Puri on 03-Apr-2012 12:27 pm
What do you mean by saying this?
  • Reply
  •  2 Like
  •  2 Dislike
  • Report
  by jesna on 22-Mar-2012 10:28 am
This one is the right program. Thanks for sharing Sachin!
  • Reply
  •  3 Like
  •  3 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
  •  3 Like
  •  2 Dislike
  • Report
  by Brijesh on 28-Dec-2011 01:19 pm
This is right program....
  • Reply
  •  5 Like
  •  2 Dislike
  • Report
  by viv on 13-Oct-2011 03:16 pm
thanx buddy...
  • Reply
  •  3 Like
  •  2 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
  •  3 Like
  •  3 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
  •  5 Like
  •  15 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
  •  2 Like
  •  1 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
  •  3 Like
  •  3 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
  •  176 Like
  •  108 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
  •  6 Like
  •  14 Dislike
  • Report