Header Ads

26 - WAP to determine Armstrong of a Number in C

This program finds the Armstrong value of a given Number in C.

An Armstrong number is a number such that the sum of its digits raised to the third power is equal to the number itself. For example, 371 is an Armstrong number, since 3*3*3 + 7*7*7 + 1*1*1 = 371.
#include <stdio.h>

//Main Function program
int main()
{
 //Variable declaration
 int number, value, remainder, result = 0;

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

 value = number;
 //Checking if value is 0.
 while (value != 0)
 {
         remainder = value % 10;
         result = result + remainder*remainder*remainder;
         value = value / 10;
     }

 //Checking if both Number & obtained result is equal.
     if(result == number)
         printf("'%d' is an Armstrong Number!\n",number);
     else
         printf("'%d' is not an Armstrong Number!\n",number);

     return 0;
}

Program Output:

No comments