8.02.2012

print Armstrong number range

Q. Write a C program to accept a number from user and print all the Armstrong number that are less then or equal to user number.
or
Q. write a C program to print Armstrong number from 1 to 1000.

Ans.

/*C program to printing armstrong number between a specific range*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,d1,d2,d3,tmp,st;
 printf("Enter ending number: ");
 scanf("%d", &num);
 for(st=1; st<=num; st++)
 {
  d1=st-((st/10)*10);
  d2=(st/10)-((st/100)*10);
  d3=(st/100)-((st/1000)*10);
  tmp=(d1*d1*d1)+(d2*d2*d2)+(d3*d3*d3);
  if(tmp==st)
     printf("\nArmstrong number is: %d",tmp);
 }
 getch();
 return 0;
}

/************Output************/


Output for print aremstrong number 1 to 786 C program
Screen shot for print aremstrong number to a specific range

Related Programs:

  1. Search Armstrong number C program
  2. Flowchart for check a number is Armstrong or not
  3. Amicable number C program
  4. Perfect number C program

No comments:

Post a Comment