Professional Documents
Culture Documents
1. An “Armstrong” number is one whose sum of digits raised to the power three equals the
number itself. For example, 371 is an Armstrong number because 3^3 + 7^3 + 1^3 = 371.
Write a Program/Function bool isArmstrong(int n) that takes as input an integer in
[1,1000], and returns true if the number is an Armstrong number or false otherwise.
3. Write a C++ Program/Function (Dec2Base(int Dec,int Bas)) to enter int decimal number,
and integer Base number [0-9]. The function should return the converted integer number
from decimal to the numbering system base.For example, if the input is 13 and the base
is 2 the returned number should be an integer 1101, or if the input is 5349 and base is 8,
the returned value should be integer 12345.
4. Write three functions using nested loops that displays the following patterns:
0 1 2 3 4 0 3 3 3 3 16 8 4 2 1
0 1 2 3 4 2 0 3 3 3 8 4 2 1
0 1 2 3 4 2 2 0 3 3 4 2 1
0 1 2 3 4 2 2 2 0 3 2 1
0 1 2 3 4 2 2 2 2 0 1
5. (Bonus question) Write C++ code to switch the values of 2 variables with the XOR
operation ^. XOR works with two arguments. It turns both arguments into their binary
representations, and for each bit, returns 1 if they are different, 0 otherwise. The return
value is the decimal representation of the new binary.
Note: (Google the algorithm Not the C++ code)