/*
* Program to print Armstrong number between range m and n
* Armstrong number is nothing but sum of cubes of digits of number is
* equal to the number
* ex: 153 is Armstrong number since 1^3+5^3+3^3=153
* Program to print Armstrong number between range m and n
* Armstrong number is nothing but sum of cubes of digits of number is
* equal to the number
* ex: 153 is Armstrong number since 1^3+5^3+3^3=153
* there are very few numbers hold above property; execute
* below program to find all numbers
* b/w m and n
*/
#include <stdio.h>
void is_armstrong(int num)
{
int sum=0, n, d;
n=num;
while(n){
d=n%10; /* extract digits of number*/
sum=sum+(d*d*d); /*take sum of them */
n=n/10;
}
if(sum == num) /*sum is same as number then it is Armstrong number*/
printf("%d\n", sum);
}
int main()
{
int i,n,m;
printf("Enter range \n");
scanf("%d%d", &m, &n);
for(i=m;i<=n;i++){
is_armstrong(i);
}
return 0;
}
*/
#include <stdio.h>
void is_armstrong(int num)
{
int sum=0, n, d;
n=num;
while(n){
d=n%10; /* extract digits of number*/
sum=sum+(d*d*d); /*take sum of them */
n=n/10;
}
if(sum == num) /*sum is same as number then it is Armstrong number*/
printf("%d\n", sum);
}
int main()
{
int i,n,m;
printf("Enter range \n");
scanf("%d%d", &m, &n);
for(i=m;i<=n;i++){
is_armstrong(i);
}
return 0;
}
This comment has been removed by the author.
ReplyDeleteArmstrong program in C
ReplyDeletegreat post