Home » C program to Check Armstrong Number with order N

C program to Check Armstrong Number with order N

Learn about C program to Check Armstrong Number of order N in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

C program to Check Armstrong Number of order N

General an Armstrong number does the sum of the cube of the digits of given number. In the below program, you can specify the order of the number manually.

Program:

 #include<stdio.h>
 #include<math.h>
 int main()
 {
      int number, temp, n, remainder, sum=0;

      printf("Enter number: ");
      scanf("%d", &number);

      printf("Enter order: ");
      scanf("%d", &n);

      temp = number;
      while( number != 0 )
      {
          remainder = number%10;
          sum += pow(remainder, n);
          number /= 10;
      }

      if(temp == sum)
          printf("%d is an Armstrong number of order %d.\n",temp,n);
      else
          printf("%d is not an Armstrong number of order %d.\n",temp,n);

      return 0;
 } 

Output:

Enter number: 153
Enter order: 3
153 is an Armstrong number of order 3.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to check Armstrong number of order Three
C program to find the perfect number using the Function