answersLogoWhite

0


Best Answer

Sorry. I had to delete the older version, for it was written in C++, while the questioner had asked one in C. So here it is. In fact, I will give the questioner a bonus, it will print not only Armstrong numbers but all Narcissistic numbers (here the power to which the individual digits should be raised before being added to each other can be any integer. Clearly Armstrong numbers form a subset of these numbers, with the power equal to three), and that too not only upto 10000, but upto the maximum number a C compiler can process. Enjoy!

#include

#include

main()

{

int m=1,b;

int a[200],i,j,k,l;

while (m<=2147483647)

{

b=m;

i=0;

while (b>=1)

{

a[i]=(b%10);

b=floor(b/10);

++i;

}

for (j=1;j<=9;++j)

{

k=0;

for (l=(i-1);l>=0;--l)

k+= pow(a[l],j);

if (k==m)

goto sexy;

}

goto label;

sexy: printf("%d (raise every digit to power of %d)\n",m,j);

label: ++m;

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

#include
#include
using namespace std;
int main(void)
{
int upper,lower;
cout<<"Enter the limits"<cin>>lower>>upper;
for(int i=lower;i<=upper;i++)
{
int temp=i;
int sum=0;
int count=0;
while(temp>0)
{
temp=temp/10;
count++;
}
temp=i;
while(temp>0)
{
n=temp%10;
temp=temp/10;
int cal=pow(n,count);
sum=sum+cal;
}
if(sum==i)
cout<<"Armstrong Numbers are"<}
return 0;
}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

//This program checks whether or not a number is palindrome #include #include


void main()
{
int rem,sum=0,n,num;


clrscr();
printf("Enter a number\n");
scanf("%d",&num);
n=num;
while(n!=0)
{
rem=n%10;
n=n/10;
sum+=rem*rem*rem;
}
if(sum==num)
printf("%d is an armstrong",num);
else
printf("%d is not armstrong",num);
getch();
}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to print Armstrong numbers in a given range?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write a program that removes all occurrences of a given X in a given sequence of numbers?

You do nothing! A sequence of numbers will contain no X and so nothing needs doing!


How do you write a c program sum of ODD Numbers in the Given Range?

Reference: cprogramming-bd.com/c_page4.aspx#ODD%20 Numbers


How do you write a program that calculates the sum of the matrix elements given numbers?

ring me and ill explain - 086 22222222222222227 ring me


Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i &lt; 100; i+=2) { System.out.println(i); }


How do you write a program to find out the percentage of given numbers using the structure in C?

Count all the given numbers then count all the numbers of a given value. Divide one by the other and multiply by 100. For instance, if there are 50 numbers in total and 5 of them have the value 42, then the percentage of numbers with the value 42 is 5 / 50 * 100 = 10%.


Write a C program to extract a given word from a file?

program to extract a given word from a file


How can you write a program specification for a given report?

It is your face


How do you write a fraction or decimal that has a value between the given numbers?

Without knowing what the numbers are, I would suggest taking the mean of the given numbers.


How do you write a c program sum of ALL Numbers in the Given Range using for loop?

Poor Boy. We do not do your homework here.


How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)