Print the armstrong number using While Loop in C


This program is about print the armstrong number between the given limits using While Loop

Source Code

#include<stdio.h>
int main()
{
  int i,n,h,arms=0,a,b,c,d,e;
  printf("\nEnter the starting value:");
  scanf("%d",&i);
  printf("\nEnter the Ending value:");
  scanf("%d",&n);
  printf("\nArmstrong numbers:");
  while(i<=n)
  {
    a=i/10;//12
    b=i%10;//8
    c=a/10;//1
    d=a%10;//2
    b=b*b*b;
    c=c*c*c;
    d=d*d*d;
    e=b+c+d;
    if(i==e)
    {
      printf("\n%d",i);
      arms++;
    }
    i++;
  }
  printf("\nTotal number of armstrong values:%d",arms);
  return 0;
}
 
To download raw file Click Here

Output

Enter the starting value:100
Enter the Ending value:999
Armstrong numbers:
153
370
371
407


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes