Discussion Forums

New User? Please read instructions!

What is armstrong number and need C program to find armstrong number  

  RSS

thiyagarajan
Eminent Member
Joined: 2 months  ago
Posts: 26
27/01/2017 9:20 am  

Please provide C program to find armstrong number


ReplyQuote
prakash
Eminent Member
Joined: 2 months  ago
Posts: 20
30/01/2017 9:50 am  

What is Armstrong number?

Sum of a number's digits raised to the power total number of digits is armstrong number.

Armstrong numbers example: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634 etc

Explanation: 

3 = 3^1 = 3

153 = 1^3 + 5^3 + 3^3 = 153

Non-Armstrong numbers:

156 = 1^3 + 5^3 + 6^3 . This value is equal to 342. So, 156 is not an armstrong number

To find whether a number is Armstrong number or not, please use below C program.

#include <stdio.h>

int main()

{

   int n, sum = 0, t, remainder;

   printf("\nPlease enter a number to find whether it is an armstrong or not");

   scanf("%d",&n);

 

   t = n;

 

   while( t != 0 )

   {

      remainder = t%10;

      sum = sum + remainder*remainder*remainder;

      t = t/10;

   }

   if ( n == sum )

      printf("\nThe number %d is an armstrong number", n);

   else

      printf("\nThe number %d is not an armstrong number", n);

   return 0;

}

 

Edited: 2 months  ago

ReplyQuote
fzjj
 fzjj
New Member
Joined: 14 hours  ago
Posts: 1
30/03/2017 6:19 am  

Hi Prakash,

In the while loop, I see that we have remainder brought to the third power. However, from the definition of what an armstrong number is that you listed, it looks like for a number with 1 digit, it will be raised to the 1 power, a power with 2 digits, each digits will be raised to the 2 power and then we find the sum of that. Hence, remainder will not always be raised to the third power but rather to the number of digits the number has. For a more explicit example, 1634 is an armstrong number because it has 4 digits and 1634 = 1^4 + 6^4 + 3^4 + 4^4.


ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!