Discussion Forums

New User? Please read instructions!

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

  RSS

thiyagarajan
(@thiyagarajan)
Eminent Member
Joined:2 years  ago
Posts: 26
27/01/2017 9:20 am  

Please provide C program to find armstrong number


ReplyQuote
prakash
(@prakash)
Eminent Member
Joined:2 years  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;

}

 


ReplyQuote
fzjj
 fzjj
(@fzjj)
New Member
Joined:2 years  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
prashantrajpoot
(@prashantrajpoot)
New Member
Joined:2 years  ago
Posts: 1
04/04/2017 6:12 pm  

 

 

 

#include<stdio.h>

#include<math.h>

void main()

{

int number, a, b, c, sum=0, count=0;

printf("\n Enter the number");

scanf("%d",&number);

a=number;

b=a;

while(a>0)

{

count++;

a=a/10;

}

while(b>0)

{

c=b%10;

sum=sum+pow(c,count);

b=b/10;

}

printf("\n sum=%d",sum);

if(sum==number)

printf("\n The number is Armstrong");

else

printf("\n The number is not Armstrong");

getch();

}


ReplyQuote
Share:

OTHER C PROGRAMS:

  1. C program for prime number
  2. C program for factorial
  3. C program for fibonacci series
  4. C program for palindrome
  5. C program for swapping 2 numbers with and without temp variables
  6. C program to find leap year
  7. C program to find armstrong number
  8. C program to find simple and compound interest
  9. C program to find largest of given 3 numbers
  10. C program to find smallest of given 3 numbers
  11. C program to convert lower case into upper case and vice versa
  12. C program to find sum and average of given 3 numbers
  13. C program to sum up all individual digits
  14. C program to reverse given number
  15. C program to reverse given string
  16. C program to find strong number
  17. C program to find square and cube of given number
  18. C program to print hello world without using semi colon
  19. C program to sort given names in alphabetical order
  20. C program to copy content of one file to another
  21. C program to sort given numbers in ascending order
  22. C program to sort given numbers in descending order
  23. C program to search given number in an array
  24. C program for recursive function
  25. C program for calculator application
  26. C program for bank application
  27. C program to check given number is perfect number or not
  28. C program to find array size
  29. C program to find whether given character vowel or not
  30. C program to check whether given number is positive or negative
  31. C program to find sum of n numbers
  32. C program to compare 2 numbers without if statement
  33. C program to generate random numbers
  34. C program to compare 2 arrays whether they are equal or not
  35. C program to print number from 1 to 500 without using any loop conditions
  36. C program to insert an element into an array
  37. C program to delete an element from an array
  38. C program to find hcf (gcd) and lcm
  39. C program to print diamond pattern
  40. C program to print pascal triangle
  41. C program to add two complex numbers
  42. C program for binary search
  43. C program for linear search
  44. C program for matrix addition
  45. C program for matrix multiplication
  46. C program for bubble sort
  47. C program for insertion sort
  48. C program for selection sort

Share this website !!!
Facebook Twitter Linkedin

  
Working

Please Login or Register