Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.80/5 (5 votes)
See more:
how to write a program in Armstrong number in 1 to 1000.
Posted
Updated 31-Dec-20 16:27pm
Comments
Sandeep Mewara 26-Oct-12 15:27pm    
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

If you mean "how to write a C program for finding Armstrong's numbers in the range {1,2,..1000}?" then I suggest you a brute force approach: iterate on every number of such interval and check if they satisfy the requirement.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Oct-12 16:07pm    
Pretty much agree: I cannot see a simple way to make if more efficient. Well, a 5.
--SA
CPallini 26-Oct-12 16:10pm    
Thank you.
A quick search yielded this result: armstrong number c program[^].
You can use it to write a program to check all the numbers in the range.

Hope it helps.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Oct-12 16:08pm    
Agree, a 5. I would prefer OP did it by himself -- not a rocker surgery. Very often, we won't have people capable of writing software solutions. :-(
--SA
here i have modified the program from Solution 2's link, it will tell you all the armstrong number from 0 to 1000

C
#include <stdio.h>

main()
{
   int number, sum = 0, temp, remainder;
   for( number=0; number<=1000; number++)
   {
      temp = number;
      sum=0;
      while( temp != 0 )
      {
         remainder = temp%10;
         sum = sum + remainder*remainder*remainder;
         temp = temp/10;
      }

      if ( number == sum )
         printf("%d is an armstrong number.\n", number);
      }
   return 0;
}
 
Share this answer
 
v2
Comments
CPallini 26-Oct-12 13:26pm    
Did you check it (it doesn't produce {3, 4, 5, 6, 7, 8, 9})?
BTW have my 5 to balance the univoter.
psychic6000 28-Oct-12 12:14pm    
then those must not be armstrong number...
CPallini 28-Oct-12 16:51pm    
...or simply the program is wrong.
They are Armstrong's numbers (every number in {0,1..,9} set is an Armstrong's number because each of them is single digit hence trivially satisfy the requirement).
You program checks only for three-digits Armstrong's numbers (it includes by accident 0,1 too).
psychic6000 29-Oct-12 12:13pm    
a number is armstrong no, if you cube all the digits in it and sum them and you get your number again... if this deification is incorrect then i am wrong
x is armstrong if (x^3)=x (for single digit no)
xy is armstrong if (x^3)+(y^3)=xy (for two digit no),
CPallini 29-Oct-12 12:29pm    
Either you are wrong or Wikipedia is (or both :-) ):
http://en.wikipedia.org/wiki/Narcissistic_number

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900