Armstrong number program in C - Programmer's Mind


Armstrong Number:

An n-digit Number is said to Armstrong number if sum of the nth powers of individual digits of that number is equal to that same number.

 void armstrong(num) {
  int sum = 0, temp = num, noOfDigits = 0;
  while (temp > 0) {
    noOfDigits++;
    temp /= 10;
  }
  temp = num;
  while (temp > 0) {
    sum += pow(temp % 10, noOfDigits);
    temp /= 10;
  }
  if (sum == num) {
    printf("\n%d is an armstrong Number", num);
  } else {
    printf("\n%d is Not an Armstrong Number", num);
  }
}

Output:








Try this program with various inputs and find the numbers which are Armstrong.
Some of the Armstrong numbers are 153,371,1634.............
Try the programs for Strong Number and Perfect Number





Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment