Question: Please code this problem in C++ An Armstrong number is an n -digit number that is equal to the sum of the n th powers

Please code this problem in C++

An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its digits. So, for instance, because 61 = 6, and 14 + 64 + 34 + 44 = 1634, both 6 and 1634 are Armstrong numbers.

Write a function that takes as an input parameter an integer. The function then calculates and prints out all Armstrong numbers between 1 and that number. The function returns a count of the number of Armstrong numbers

FYI, for testing purposes, the following are the Armstrong numbers:

1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, ..You can stop testing around 10000 or youll be waiting a while.

NOTE: normally I am all for short helper functions. However, in this case, I would like this to all be written in one function

NOTE: For arrays of ints, you can create the arrays manually or you can generate them using the random number generator. For random numbers in c++, you must first seed the random number generator with the current time (down to the millisecond). You do this by first including the time.h library:

#include

Then either in your main or in the function that is generating the random numbers, you must seed the random number generator as follows:

srand(time(NULL)); //You only need to do this once

After that you can generate random numbers as follows:

int x = rand(); // generates a random number between 0 and a max number defined in stdlib

Question: if rand() generates any random number between 0 and some huge number, how can you take that number and modify it to be between 0 and 100?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!