473,799 Members | 3,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("armstro ng number\n");
return 0;
}

May 14 '07 #1
2 12545
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("armstro ng number\n");
return 0;
}
int is_armstrong3(i nt 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("armstro ng 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
12028
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 1 and 100, but I want to switch things around. I want to be able to put in my own number and have the computer guess it. I already know how to make it guess (by using randrange) but I'm having a hard time making it smarter. (Like guessing higher...
6
7755
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 to have to cycle through the entire XML file in order to do this. When I am importing the XML file, I want to display record X of XX. Any ideas would be appreciated. Thanks in advance.
11
7164
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 the exact code ( well maybe a little) but the logic or algorithm to tell whether or not a number is prime....
1
1962
by: ipscec | last post by:
how to make armstrong program? pls reply if anyone knows..........i'll be very thankful
4
2540
by: himanshu srivastava | last post by:
how to write a program that will find all armstrong numbers between 1 to 100000
11
6154
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
9059
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 be able to represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63, which is about 2 ^ 416, so we're talking about maybe a 512-Bit number. So I need to be able to do division and multiplication on a 512-Bit number. Has anyone here...
1
1554
by: siddhantpratap | last post by:
write a cpp pogram to find all armstrong between 1 to 1000
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.