|
| |
Exercise 4-2-1
Answer these questions in class or for homework.
- Declare a reference to life, a boolean array. Solution
- Declare and allocate memory for a 1000 element integer array named price.
Solution
- Declare an integer variable constant named ELEMENTS to have a value
of 13. Solution
- Declare and allocate memory for a double array named numbers. The
number of elements in the array is contained in a variable constant named ELEMENTS.
Solution
- Initialize an array named small with the values of 23.34, 45.1,
75.4, and 12.3. Solution
- Use a loop to assign the values 0, 3, 6, 9, ..., 36 to the elements of an
array named triples. Solution
- Create an int array named sample with 3 elements. Create a loop that will use keyboard input to ask for user input for the values of the 3 elements.
e.g.
Enter the value of element #0: 23
Enter the value of element #1: -23
Enter the value of element #2: 3
Solution
- Use a loop to add up the values in the array in question 6, triples,
and display the answer. Hint: use this code as a base for the loop. Solution
- Use an if statement inside a loop to add up the values in the array named triples
that are divisible by 4. Display the answer. Hint: use modulus operator.
Solution
- Make a menu driven program that will allow the user to do the following
options:
- enter 10 elements into an array of 10 elements
- display the elements
- find the smallest value in the array
Here is a section of code to help
you get started with the menu driven program format.
You are given a menu driven program that will repeat until you enter in
the letter Q (or q).
You have to fill in the 3 sections to complete tasks a, b, and c.
-
|