Header Ads Widget

Responsive Advertisement

Armstrong Numbers in a Given Range

 


#include <math.h>
#include <stdio.h>
int main() {
  int  number, q, rem, count = 0,start,end;
  int result = 0;
  printf("Enter Two Number : ");
  scanf("%d%d",&start,&end);
   
  if(start>end)
    { start=start+end;
    end=start-end;
    start=start-end;
    }
    printf("The Armstrong Numbers between %d and %d are :",start,end);
    

for(number=start; number<=end; number++)
  { 
     q=number;
   
    // This is for Digits Calculation
  
    while(q!=0)
    {
    q=q/10;
    count++;
    }
    q=number;
   
    //This is for Armstrong Number Calculation

    while(q!=0)
    {
    rem=q%10;
    result=result+pow(rem,count);
    q=q/10;
    }
    if(result==number)
    printf("%d ",number);
  
    count=0;
    result=0;
  }
return 0;
}


Post a Comment

0 Comments