answersLogoWhite

0

#include<iostream>

#include<vector>

unsigned count_digits (unsigned num, const unsigned base=10)

{

unsigned count=1;

while (num/=base) ++count;

return count;

}

class number

{

std::vector<unsigned> value;

unsigned base;

public:

number (const unsigned _value, const unsigned _base=10): value {}, base {_base} { *this = _value; }

number& operator= (const unsigned _value);

operator unsigned () const;

bool is_narcissistic () const;

};

number& number::operator= (unsigned _value)

{

unsigned count = count_digits (_value, base);

value.resize (count);

while (count)

{

value[value.size()-count--] = _value%base;

_value/=base;

}

return *this;

}

number::operator unsigned () const

{

unsigned num = 0;

for (unsigned index=0; index<value.size(); ++index)

num += value[index]*static_cast<unsigned>(std::pow (base, index));

return num;

}

bool number::is_narcissistic () const

{

unsigned num = 0;

for (unsigned index=0; index<value.size(); ++index)

num += static_cast<unsigned>(std::pow (value[index], value.size()));

return num == static_cast<unsigned> (*this);

}

unsigned main()

{

const unsigned min=1;

const unsigned max=100;

std::cout << "Narcissistic numbers in the range " << min << " through " << max << ":\n\t";

for (unsigned n=min; n<=max; ++n)

if (number(n).is_narcissistic())

std::cout << n << ' ';

std::cout << '\n' << std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

C plus plus program to print number patterns?

bghjg


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


What is the contact number for family health plus insurance?

(1-877-934-7587) Family Health Plus (adult insurance program)


How to restart c plus plus program?

Exit the program and relaunch it.


How do you make a program that display odd number from one to twenty in c plus plus?

for (int i=1; i&lt;20; i+=2) printf ("%d\n", i);


Can you program games with c plus plus?

Yes, you can program games with C++.


Is there an answer book for the A plus program?

The A Plus Program is an initiative, not a test. So no, there is no answer book.


What is the Formula for calculating lower quartile on excel?

.25 * The Number of items in the list plus 1 equals the Item Number that is the lower quartile.


How many children does Billie Joe Armstrong have?

billie joe Armstrong has two kidz plus 999999998 so like a billion


What are the benefits of the Borders Rewards program?

There are a number of benefits to the Borders Rewards program, including coupons for in-store and online purchases, free shipping on orders above $25 and 30% off the list price of hard cover best sellers. There is also a Rewards-Plus option that increases the discount on hard cover best sellers to 40% off, 20% off the list price of selected hard cover titles, 10% off the list price of most other items and free shipping from the Borders website.


Why does sometimes when you run a program it will execute the previous program instead the current open program in C plus plus?

Because you aren't careful enough.


What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


What are all the even numbers in the world?

It is impossible to list all the even numbers in the world - there is an infinite number of them. Suppose you were to list all the even numbers you could find in order, starting 0, 2, 4, 6 and so on up to some last number. I could easily point out another even number in the world not in the list - I would simply add 2 to the last number in the list and declare that it is not in the list. You would have to add it, but then I would point out that this number plus 2 is not in the list and needs to be added. We would go on like this forever - whatever last number you give for the list, I simply add 2 and point out there is another even number in the world not on the list.


What is the C plus plus plus program for the addition of two numbers?

#include&lt;iostream&gt; int main() { int num1, num2; std::cout &lt;&lt; "C++ addition program" &lt;&lt; std::endl; std::cout &lt;&lt; "Enter a number: "; std::cin &gt;&gt; num1; std::cout &lt;&lt; "Enter another number: "; std::cin &gt;&gt; num2; std::cout &lt;&lt; "The sum is " &lt;&lt; num1 + num2 &lt;&lt; std::endl; }


Lint is a compiler b a interactive debugger c a cinterpreter d a tool for analysing c plus plus program?

d a tool for analysing c plus plus program


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


What in the highest number in the world?

The list of numbers continues forever so there is not a largest number. We sometimes call the 'final number' infinity but it is not a fixed number - it has no value. Think about this: Let n be any number What must n+1 be? Well, it is a number plus another number so it must also be a number. That means that the list of numbers continues forever and there is no largest number.


Do I need a C plus plus program to print PASCAL's triangle?

No.


Is there any benefit to a C plus plus program of round robin?

No.


How does algorithm and c plus plus program get along?

They are bosom-friends.