473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

armstrong number

an armstrong number of three digits is an integer such that the sum of
the cubes of its digits is equal to the number itself. for example,
171 is an armstrong number since 3**3+7**7+1**1=371.
i have try but not succed.kindly help me .
here is what i did :

int main()
{
int a,b,n,s=0;
printf("enter no");
scanf("%d",&n);
b=s;
while(n>10)
{
a=n%10;
s=s+(a*a*a);
n=n/10;
}
s=s+(n*n*n);
if(b==s)
printf("armstrong number\n");
return 0;
}

May 14 '07 #1
2 12520
ashu said:
an armstrong number of three digits is an integer such that the sum of
the cubes of its digits is equal to the number itself. for example,
171 is an armstrong number since 3**3+7**7+1**1=371.
More generally, an Armstrong number is a number which, expressed in base
b, has n digits such that the sum of its (base b) digits, each raised
to the power n, is equal to the number itself. Below, we confine
ourselves to three base ten digits, for simplicity.

171 is not an Armstrong number because the cubes of 1, 7, and 1 are 1,
343, and 1 respectively. Their sum is 345. 371 is, however, an
Armstrong number, but this has nothing to do with raising 7 to the
power 7 or 1 to the power 1.
i have try but not succed.kindly help me .
here is what i did :

int main()
{
int a,b,n,s=0;
printf("enter no");
Calling a function without a valid function prototype in scope invokes
undefined behaviour. You forgot to #include <stdio.h>

fflush(stdout) if you want your prompt to appear before you block for
input.
scanf("%d",&n);
scanf returns an important value. Check that it's the right value. If it
isn't, you know something went wrong.
b=s;
while(n>10)
{
a=n%10;
s=s+(a*a*a);
n=n/10;
}
s=s+(n*n*n);
if(b==s)
printf("armstrong number\n");
return 0;
}
int is_armstrong3(int n)
{
int is = 0;
if(n 99 && n < 1000)
{
int h = n / 100;
int t = (n / 10) % 10;
int u = n % 10;
if(h * h * h + t * t * t + u * u * u == n)
{
is = 1;
}
}
return is;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 14 '07 #2
ashu wrote:
an armstrong number of three digits is an integer such that the sum of
the cubes of its digits is equal to the number itself. for example,
171 is an armstrong number since 3**3+7**7+1**1=371.
See Richard's comment on the example.
i have try but not succed.kindly help me .
here is what i did :

int main()
{
int a,b,n,s=0;
printf("enter no");
scanf("%d",&n);
b=s;
while(n>10)
{
a=n%10;
s=s+(a*a*a);
n=n/10;
}
s=s+(n*n*n);
if(b==s)
printf("armstrong number\n");
What values are being compared and why? That should point you to your
problem.

Also, if the power and the number of digits is required to be the same
by definition of an Armstrong number, then the test may fail for numbers
with the wrong number of digits.

--
Thad
May 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between...
6
by: Milo Woodward | last post by:
Does anyone know how to retrieve the number of records an XML file contains with a vb.net method? I can read through an entire XML file, import records into SQL Server, etc. However, I don't want...
11
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not...
1
by: ipscec | last post by:
how to make armstrong program? pls reply if anyone knows..........i'll be very thankful
4
by: himanshu srivastava | last post by:
how to write a program that will find all armstrong numbers between 1 to 100000
11
by: sriparna mukhopadhyay | last post by:
Sir/Madam I would be very glad if you answer the above written problem in C prog code.
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
I need a Big Number library. I've been considering switching my project to C++ but at the moment I'm exploring the avenue of keeping it in C. What's the best Big Number library for C? I need to...
1
by: siddhantpratap | last post by:
write a cpp pogram to find all armstrong between 1 to 1000
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.