Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

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;

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.

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.

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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc