Armstrong Numbers Between Two Intervals

Armstrong numbers between two intervals:-

To identify the Armstrong number between two intervals in C programming, the user is required to insert integer numbers. A n digit number is known as an Armstrong number, when the sum of the values of the digits raised to nth power is equal to the number itself. For example: 153 = 13+53+33=153

Ex:- basically we know that Armstrong number in given range 0 to 999  are 1 2 3 4 5 6 7 8 9 153 370 371 407.

Armstrong numbers between two intervals in C programming

Working:-

Step 1: Start

Step 2: Insert the start and end value

Step 3: Repeat from I = start value to end value

Step 4: Repeat the process until the temporary number is not equal to 0.

Step 5: Remainder = temp%0

Step 6: The result should be equal to result plus the power (remainder n).

Step 7: temp = temp/10

Step 8: If the value of the result is equals to the value of number then print the number

Step 9: Else repeat the steps until the end number is encountered.

Step 10: Stop

 

C Program:-

#include<stdio.h>
int main()
{
     //For initializing variables
      int start, end, i, temp1, temp2, rem, n = 0, result = 0;
     //user give start and end point of a number
    printf("Insert the start value and end value :");
    scanf("%d %d", &start, &end);

    //to display pint of range
    printf("\n Armstrong nums between %d an %d are: ", start, end);

     //for use this loop to store all number in given range
    for(i = start + 1; i < end; ++i)
    {
         //store a duplicity value of given range
         temp2 = i;
         temp1 = i;

      while (temp1 != 0)
      {
           //temp1 /= 10;
           temp1=temp1/10;
            ++n;
      }
      while (temp2 != 0)
      {
         rem = temp2 % 10;
         //result += pow(rem, n);
        result=result+pow(rem,n);
       //temp2 /= 10;
         temp2=temp2/10;
      }
      //check true condition if result is equal to i
        if (result == i)
        {
            //display
            printf("%d ", i);
        }
         n = 0;
       result = 0;
   }
    printf("\n");
  return 0;
}

Output:

Insert the start value and end value: 100, 500
Armstrong numbers between 100 and 500 are: 370, 371, 407.

Please Login/Signup to comment