Monday 1 September 2014

print Armstrong number range

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************/


No comments:

Post a Comment