Finding Armstrong Number

Armstrong Numbers

Program for finding Armstrong number of a three digits number.

The condition for Armstrong number is,
Sum of the cubes of its digits must equal to the number itself.

For example, 407 is given as input.
4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an Armstrong number.


Source Code



#include <stdio.h>

int main()
{
      int i, a, b, c, d;
      printf("List of Armstrong Numbers between (100 - 999):\n");

      for(i = 100; i <= 999; i++)
      {
            a = i / 100;
            b = (i - a * 100) / 10;
            c = (i - a * 100 - b * 10);

            d = a*a*a + b*b*b + c*c*c;

            if(i == d)
            {
                  printf("%d\n", i);
            }
      }  
      return 0;
}



Output



List of Armstrong Numbers between (100 - 999):
153
370
371
407

৩টি মন্তব্য:

  1. // Finding an armstrong number //

    #include
    int main()
    {
    int a,b,c,num=0;
    printf("\n Enter a positive integer: ");
    scanf("%d",&a);
    for(b=a;b!=0;)
    {
    c=b%10;
    num+=c*c*c; // note: [ the system of armstrong number is to enter the powers according to digits] //
    b/=10;
    }
    if(num==a)
    printf("%d is an armstrong number.",a);
    else
    printf("%d is not an armstrong number.",a);
    }

    উত্তরমুছুন
  2. int main()
    {
    int i, x, y, c, d;
    printf("List of Armstrong Numbers between (100 - 999):\n");

    for(i = 100; i <= 999; i++)
    {
    x = i / 100;
    y = (i - x * 100) / 10;
    c = (i - x * 100 - y * 10);

    d = x*x*x + y*y*y + c*c*c;

    if(i == d)
    {
    printf("%d\n", i);
    }
    }
    return 0;
    }

    উত্তরমুছুন