C Program to Generate ArmStrong Numbers

Generating Armstrong Numbers in C Program with Example code


By Using this program you can generate Armstrong number with the given limit. By using the input from user (user can specify the limit) we can generate Armstrong Number using Loop from one to the entered number and check and the each incremented value in the loop will performed to check whether Armstrong number or not. If it is an Armstrong number then it will be printed else it will not be printed. As we know Armstrong number is one if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as
33 + 73 + 13 = 371
Some of the Armstrong number are 1, 153, 370, 407.


#include<stdio.h>
#include<conio.h>

int main()
{
int r;
long int num = 0, i, sum = 0, temp;
printf("Enter the maximum limit to generate Armstrong number ");
scanf("%ld",&num);
printf("Following armstrong numbers are found from 1 to %ld
",num);
for( i = 1 ; i <= num ; i++ )
{
temp = i;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( i == sum )
printf("%ld
",i);
sum = 0;
}
getch();
return 0;
}



Related Topic Top PPC Advertising Program Ad Networks List
Fibonacci Program in C Language
C Program Prime Number
C Program for Armstrong Number
Prime Number Program in Java

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback