Code Scrappers


Armstrong number C program


              #include<stdio.h>
              #include<stdlib.h>

              void main()
              {
                  int n, rem, originalnum;

                  int  res = 0;

                  printf("Enter a three digit integer: ");

                  scanf("%d", &n);

                  originalnum = n;

                  while (originalnum != 0)
                  {
                      rem = originalnum % 10;

                      res = res + rem*rem*rem;

                      originalnum = originalnum / 10;
                  }

                  if(res != n)
                  {
                      printf(" NO. %d is not an Armstrong number\n",n);
                  }
                  else
                  {
                      printf("YES. %d is an Armstrong number\n",n);
                  }
              }
          



Output

    Enter a three digit integer: 156

    NO. 156 is not an Armstrong number