C Program to Check Armstrong Number?


A number is called an Armstrong number if the sum of cubes of digits of the number is equal to the number itself. It is a mathematical concept usually used in programming to build basic logic of the programmer

Input:370
Output:370 is an Armstrong Number

Explanation

370 = 3*3*3 + 7*7*7 + 0*0*0
= 27 + 343 + 0
= 370

Example

include <iostream>
using namespace std;
int main() {
   int n, num, rem, sum = 0;
   cin >> n;
   num = n;
   while(num != 0) {
      digit = num % 10;
      sum += digit * digit * digit;
      num /= 10;
   }
   if(sum == n)
      printf("%d is an Armstrong number.", n );
   else
      printf("%d is not an Armstrong number.",n);
   return 0;
}

Updated on: 19-Aug-2019

278 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements