c program to find and print armstrong numbers between 100 and 999

Armstrong numbers:

Input : Say 153.
Calculating armstrong number: 
  153=(1*1*1)+(5*5*5)+(3*3*3)= 1+125+27 =153  
If input equals output, 153==153, 153 is armstrong number.

#include<stdio.h>
#include<conio.h>
void main()
{
  int num, n, rem;
  int cube=0, sum; 
  printf("n Armstrong numbers between 100 and 999 are: n");
  for(num=100;num<=999;num++)
  {
    sum=0;
    n=num;
    do
    {
      rem=n%10;
      cube=rem*rem*rem;
      sum=sum+cube;
      n=n/10;
    }while(n>0);
    if(num==sum)
    {
      printf("n%d is armstrong number",num);    
    }
  getch();
}

Ouput:

Armstrong numbers between 100 and 999 are:

153 is armstrong number
370 is armstrong number
371 is armstrong number
407 is armstrong number

 

Leave a Reply

error: Content is protected !!
%d bloggers like this: