C program to check whether the given number is an Armstrong number

In this program we will use while loop to check whether given number is Armstrong number or not. 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, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371

Code for C program to check whether the given number is an Armstrong number

#include <stdio.h>
#include <conio.h>

int main()
{
  int num, remainder, total = 0, temp;
  printf("Enter the number=");
  scanf("%d", &num);
  temp = num;
  while (num > 0)
  {
    remainder = num % 10;
    total = total + (remainder * remainder * remainder);
    num = num / 10;
  }
  if (temp == total)
    printf("This number is Armstrong number");
  else
    printf("This number is not Armstrong number");
  return 0;
}

Output

Enter the number=371
This number is Armstrong number
Enter the number=53
This number is not Armstrong number

Read: C program to find reverse of a number


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment