Testing.

Saturday, 21 January 2017

C programming language: C program to print list of Armstrong numbers.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,j,sum=0,rem,cnt=0;
printf("\nEnter Value: ");
scanf("%d",&n);
for(num=153;num<=n;num++) //Here have initialize num by 153 because, 153 is the smallest                                                                   armstrong number. 
{
sum=0;
for(j=num;j!=0;)
{
rem=j%10;
sum=sum+rem*rem*rem;
j=j/10;
}

if(num==sum)
printf("\n%d Armstrong Number: %d ",++cnt,num);
if(cnt==4)
break;
}
getch();
}

No comments:

Post a Comment