#include <stdio.h>
      
      int armstrongNumber() {
        int num, originalNum, remainder, result = 0;
        printf("Enter a three-digit integer: ");
        scanf("%d", &num);
        originalNum = num;
        while (originalNum != 0) {
          // remainder contains the last digit
          remainder = originalNum % 10;
          result += remainder * remainder * remainder;
          // removing last digit from the orignal number
          originalNum /= 10;
        }
        if (result == num)
          printf("%d is an Armstrong number.", num);
        else
          printf("%d is not an Armstrong number.", num);
        return 0;
      }
      
      C language logo

      Check Armstrong Number

      Codiga's C Recipes

      Check whether an integer entered by the user is an Armstrong number or not. A positive integer is called an Armstrong number (of order n) if

      abcd... = an + bn + cn + dn +

      In the case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example, 153 is an Armstrong number because

      153 = 1*1*1 + 5*5*5 + 3*3*3

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.