0% found this document useful (0 votes)
15 views2 pages

C++ Exercise 6 Warm Up Answer

Uploaded by

757032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

C++ Exercise 6 Warm Up Answer

Uploaded by

757032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: C++ Exercise 6

Warm up: (Not required to hand in)


1. Given an array:

int a[10] ={0, 2, 5, 8, 12, 24}

a. Fill out the values in the following blank that represents the array

b. Using the previous array, find out the answer of the following questions:

 i = a[6], what is the value of i? __________

 if the answer of i=a[x] is 5, then x must be _________

 let i=3, k=a[++i] -20, what is the value of k? _________

 a[5] = a[4]+3, a[5] will become _________________

 Given a[1]++, after this line of statement, a[1] will become _________

 #define SIZE (sizeof(a)/?) will determine the length of an array. Complete


the part labelled with ? __________________

2. Write a program fragment that asks user to enter 10 integer numbers into an
array of length 10

3. The Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, ….., where each number is the
sum of the two preceding numbers. Write a complete program, starting with
a[40]={0, 1}, that will fill the array with 40 Fibonacci numbers

4. Write a program in C++ to store elements in an array and print it.


Name: C++ Exercise 6

5. Read i number of values in an array and display the elements in reverse order.

6. Find the sum of all elements in an array

7. Copy the elements one array into another array

Exercise (To hand in)


1. Write a program that checks whether any of the digits in a number appear more
than once. After the user enters a number, the program prints either Repeated
digit or No repeated digit:

Enter a number: 28212


Repeated digit

2. Modify the first program so that it shows which digits (if any) were repeated:

Enter a number: 939577


Repeated digit(s): 7 9

3. Modify the first program so that:


a. It prints a table showing how many times each digit appears in the number:

Enter a number: 41271092


Digit: 0123456789
Occurrences: 1220100101

b. The user can enter more than one number to be tested for repeated digits.
The program should terminate when the user enters a number that’s less than
or equal to 0

Both features should be included in this modification.

You might also like