•
•
•
•
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
![]() |
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 11,020
Reputation:
Rep Power: 33
Solved Threads: 117
What is an armstrong number?
Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
He's referring to LANCE Armstrong, of course, and the numbers are:
1
1
1
1
1
1
First 6 times in a row!
1
1
1
1
1
1
First 6 times in a row!
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
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.
- or - more generally for an arbitrary base:
You could do this on Decimal (base 10) or even Hex (base 16)
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
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 numberArmstrong 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:
Rep Power: 0
Solved Threads: 0
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:
#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:
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- random numbers all different??? (C++)
- Overlocking Pointless? (Motherboards, CPUs and RAM)
Other Threads in the C Forum
- Previous Thread: Emulator Help!!!!!
- Next Thread: print out problem


Linear Mode