Find Armstrong number in between a range using c language

#include<stdio.h>
#include<math.h>
void armnumber(int);
int count=0;
void main()
{
  int fnum,lnum,temp,i;
  printf("this programme will help you to find armstrong number in user specified range::\n\n");
  printf("enter two numbers , in between those armstrong number will be search :: ");
  scanf("%d%d",&fnum,&lnum);
  if(fnum>lnum)
  {
    temp=lnum;
    lnum=fnum;
    fnum=temp;
  }
  printf("armstrong number(s) from %d to %d ::\n",fnum,lnum);
  for(i=fnum;i<=lnum;i++)
  {
    armnumber(i);
  }
  if(count==0)
  {
    printf("no armstrong number found in between this range...");
  }
  else
  {
    printf("\ntotal armstrong number is :: %d\n\n",count);
  }
  return;
}
void armnumber(int num)
{
  int temp,rem,res=0;
  temp=num;
  while(temp!=0)
  {
    rem=temp%10;
    res=res+pow(rem,3);
    temp=temp/10;
  }
  if(num==res)
  {
    printf("%d , ",num);
    count++;
  }
  return;
}

Post a Comment

0 Comments