answersLogoWhite

0

What is programme in c plus plus of a Armstrong number?

Updated: 8/19/2019
User Avatar

Wiki User

10y ago

Best Answer

#include <iostream>

#include <math.h> // for std::pow()

unsigned int get_length(unsigned int num,const unsigned int base=10)

{

unsigned int len=1;

while(num && (num/=base))

++len;

return( len );

}

bool is_armstrong(const unsigned int num,const unsigned int base=10)

{

unsigned int len=get_length(num,base);

unsigned int sum=0;

unsigned int tmp=num;

while(tmp)

{

sum+=(unsigned int)std::pow((double)(tmp%base),(double)len);

tmp/=base;

}

return(num==sum);

}

int main()

{

std::cout << "Armstrong series (base 10):";

for(unsigned int num=0; num<=0xffffffff; ++num)

if(is_armstrong(num))

std::cout << " " << num;

std::cout << std::endl;

return(0);

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is programme in c plus plus of a Armstrong number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Make programme for multification of three no in c plus plus?

result = a * b * c;


What are the steps to execute a c plus plus programme?

Build it, link it, run it.


Can a user compile c programme using c plus plus compiler?

Usually, but not always. For example the following is legal in C, but illegal in C++: char new [3] = "ABC";


How many keywords are there in c?

answer:32 programme to print factorial of a given number in c languages


Write a C programme to count the number of vowals present in your name?

abhimanyu


How do you write a programme to print a plus bi in c plus plus?

#include &lt;iostream&gt; int main() { std::cout &lt;&lt; "a plus bi" &lt;&lt; std::endl; return 0; }


Write a programme for substraction of two numbers in c language?

substracion of any two number program in c


How do you use this function in c programme?

I don't use that function in C programme.


Write a c plus plus programme to illustrate single inheritance?

struct A {}; // base class struct B : A {} // derived class (single inheritance).


What does Armstrong mean in C programming?

Armstrong number means 153=(1^3)+(5^3)+(3^3)


Write a programme to find greater among two numbers in c plus plus?

You could use an if, but the ternary operator is especially compact for this purpose: result = a &gt; b ? a : b;


What is the value of a b and c in the equation ax2 plus bx plus c?

any number