User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,572 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,618 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 10657 | Replies: 7
Closed Thread
Join Date: Jul 2004
Posts: 6
Reputation: smithag261 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
smithag261 smithag261 is offline Offline
Newbie Poster

Solution Armstrong numbers

  #1  
Aug 17th, 2004
I want to know how to write a program to print all Armstrong numbers between 1 and 500.
AddThis Social Bookmark Button
 
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 11,020
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 33
Solved Threads: 117
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Armstrong numbers

  #2  
Aug 17th, 2004
What is an armstrong number?
 
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Armstrong numbers

  #3  
Aug 17th, 2004
He's referring to LANCE Armstrong, of course, and the numbers are:

1
1
1
1
1
1

First 6 times in a row!
 
Join Date: Apr 2004
Posts: 3,755
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Armstrong numbers

  #4  
Aug 17th, 2004
Originally Posted by cscgal
What is an armstrong number?
What is an Armstrong number?

 
Join Date: Aug 2004
Location: india,AP
Posts: 17
Reputation: let us c is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
let us c's Avatar
let us c let us c is offline Offline
Newbie Poster

Re: Armstrong numbers

  #5  
Aug 19th, 2004
amstong numer means when u add the cubes of digits of number u should get the number.ex:407=4^3+0^3+7^3
 
Join Date: Aug 2004
Location: Hanover
Posts: 152
Reputation: cosi is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: Armstrong numbers

  #6  
Aug 19th, 2004
Start out simple. Write a function that iterates through numbers between 0 and 500, and does the sum the cubes test. Usually we just call this type of algorithm a search over parameter space. For all sorts of problems for which we have no answers, we simply search for it.

for (hundreds_digit from 0 to 5)
   for (tens_digit from 0 to 9)
      for (ones digit from 0 to 9)
          if (sum the digits^3) == number
                  print number

- or - more generally for an arbitrary base:

You could do this on Decimal (base 10) or even Hex (base 16)

for (hundreds_digit from 0 to 5)
   for (tens_digit from 0 to Base-1)
      for (ones digit from 0 to Base-1)
          // be careful about the 'sum the digits^3'
          // make sure you know what base you are in.
          // you may want to convert the number to decimal first
          if (sum the digits^3) == number
                  print number

Armstrong numbers aren't a solved problem, so you aren't going to find a closed-form formula to generate the next number. You can probably find a more clever way to perform the search over parameter space of numbers. I highly encourage you to try to make a more efficient program; it'll train your critcal thinking skills.


Ed
In a world without walls or fences,
What use are Windows and Gates.
 
Join Date: Oct 2005
Posts: 1
Reputation: jasmeet_1988 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jasmeet_1988 jasmeet_1988 is offline Offline
Newbie Poster

Solution Re: Armstrong numbers

  #7  
Oct 3rd, 2005
The program in C is(for 1-500)

#include<conio.h>
#include<math.h>
#include<stdio.h>
main()
{
int a,b,c,d,i;
for(i=500;i>=1;i--)
{
a=(i-(i%100))/100;
b=((i%100)-(i%10))/10;
c=(i%10);
d= (a*a*a)+(b*b*b)+(c*c*c);
if(d==i)
printf("%d\n",i);
}
getch();
}
:mrgreen:
 
Join Date: Apr 2004
Posts: 3,755
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Armstrong numbers

  #8  
Oct 3rd, 2005
Let sleeping threads lie.
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 6:04 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC