You are on page 1of 1

Assignment 1

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.

2. Write a C++ Program/Function (Base2Dec(int Num,int Bas)) to pass an integer number


and int Bas [0-9] number. The Function should return the converted number from
numbering system base to decimal integer number. For example, if the input is 1101 and
base is 2, the returned int value should be 13, or if the input is 12345 and int base is 8 the
returned integer value should be 5349.

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:

Pattern (a) Pattern (b) Pattern (c)

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)

Due Date: 22 February 2023.


Book a zoom meeting with Dr.Amr Badreldin to Present and Demonstrate your assignment.
Do not send your assignment by email or WhatsApp.

You might also like