Skip to main content
Logo image

Section 17.4 Array Practice

Time to practice working with arrays. Remember that practice (which automatically includes making lots of mistakes) is the best way to learn. Please pick and solve at least one of the following problems. If you get done early be sure to move on to one of the other problems!

Subsection 17.4.1 Option 1

Activity 17.1.

Write a program that does the following: Declare an array of 10 integer values and have the user enter 10 integers which you save in the array (you should use a loop here). Next, print out all 10 values the user has entered.
For example, if the user entered 45, -34, 5, 0, 1, 100, -55, ... then the output should be:
1. 45
2. -34
3. 5
4. 0
5. 1
6. 100
7. -55
...
Challenge: Write the program so that the number ’10’ above could be easily replaced with any other integer value (for example 15, or 20, etc), by changing only one value in your program. Hint: use #define .

admin.....open in new window

When you are done, please paste your code into the code submission box below:

Subsection 17.4.2 Option 2

Activity 17.2.

Write a program that declares an array of 100 floats. Fill this array with the square roots of the numbers 1 - 100 and print the result in the following form:
The square root of 1 equals 1.00000.
The square root of 2 equals 1.41421.
The square root of 3 equal 1.732051.
...
Note: In order to be able to use the square root function, sqrt(), you need to include the header file for the mathematics library using the command
#include <math.h>
at the top of your program where the other #include directives are located.

admin.....open in new window

When you are done, please paste your code into the code submission box below:

Subsection 17.4.3 Option 3

Activity 17.3.

Write a program that prompts the user to type in a sentence, and that reads the sentence, character by character, and stores it in an array of characters. Stop reading, when the array is full or the character read is \n. Next, print out the sentence in reverse.
Here is a sample output:
Enter a sentence: I love programming.
Reverse: .gnimmargorp evol I

admin.....open in new window

When you are done, please paste your code into the code submission box below: