#include<stdio.h>
#include<conio.h>
void main()
{
int r;
long number = 0, i, sum = 0, temp;
clrscr();
printf("\n\tEnter the maximum range upto which you want to find armstrong numbers : ");
scanf("%ld",&number);
printf("\n\tFollowing armstrong numbers are found from 1 to %ld\n",number);
for( i = 1 ; i <= number ; i++ )
{
temp = i;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( i == sum )
printf("\n\t%ld\n", i);
sum = 0;
}
getch();
}
#include<conio.h>
void main()
{
int r;
long number = 0, i, sum = 0, temp;
clrscr();
printf("\n\tEnter the maximum range upto which you want to find armstrong numbers : ");
scanf("%ld",&number);
printf("\n\tFollowing armstrong numbers are found from 1 to %ld\n",number);
for( i = 1 ; i <= number ; i++ )
{
temp = i;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( i == sum )
printf("\n\t%ld\n", i);
sum = 0;
}
getch();
}
No comments:
Post a Comment