Niloy007

Armstrong Number

Apr 2nd, 2021
611
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int calculateQubes(int n) {
  4.     return (n * n * n);
  5. }
  6.  
  7. int isArmstrong(int n) {
  8.     int temp = n;
  9.     int sum = 0;
  10.     while (temp > 0) {
  11.         int x = temp % 10;
  12.         sum += calculateQubes(x);
  13.         temp /= 10;
  14.     }
  15.     // printf("Sum = %d\n", sum);
  16.     return sum;
  17. }
  18.  
  19. int main() {
  20.     for (int i = 1; i <= 500; i++) {
  21.         if (isArmstrong(i) == i) {
  22.             printf("%d\n", i);
  23.         }
  24.     }
  25. }
RAW Paste Data