I wrote this program in C# to generate Armstrong numbers.I know the addition of extra method is unnecessary but it's something I've just learnt and have been practicing . So the generator only shows number till 9 no matter how large of a limit I give.
C For Loop: Exercise-30 with Solution. Write a C program to find the Armstrong number for a given range of number. Sample Solution: C Code: /.When the sum of the cube of the individual digits of a number is equal to that number, the number is called Armstrong number. For example 153. Download Check Armstrong number program. C program to check Armstrong number using function We will use long long data type in our program so that we can check numbers up to 2^64-1.
I can't see what I am doing wrong.
Pranav NachnekarPranav Nachnekar
5 Answers
Explanation for Armstrong-Number:
Sum of the cubes of its digits must equal to the number itself.
For example,
407
is given as input.4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407
is an armstrong number.![Armstrong Armstrong](http://1.bp.blogspot.com/-90M5qRI093w/TvXUhKDCP1I/AAAAAAAAAAY/PBERBsL4-n4/s1600/arm.png)
You need to calculate the sum right:
This has following output with your code (except that i incluced
0
which is also an armstrong number):M. SchenaM. Schena
Your isAmstrong formula itself seems to be wrong.
Try to use summation of Math.Pow(x % 10, 3) instead of this:
Use
Checkout Amstrong Number:
IanIan
You never check your number length power with current digit because wikipedia says;
In recreational number theory, a Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.
I fixed your method based on that like;
For example, if you call all armstrong numbers less than
10000
, withyou will get
Soner GönülSoner Gönül
![Armstrong number in c Armstrong number in c](/uploads/1/2/4/9/124982178/588489104.jpg)
seyedseyed
I have written the below code to find whether the given number is a Armstrong number or not and it worked fine
Created a new static method named Armstrong with a string parameter
If we call the method in Main method then we can get the required output
Armstrong('153');
Result :Armstrong
Similarly if we want to find whether a number is armstrong or not then keep the required number as arguments of the method and execute
Sai Ram SagarSai Ram Sagar