Professional Documents
Culture Documents
Worksheet #5
int myList(10);
for (int i = 1; i <= 10; i++)
cin >> myList;
for (int i = -1; i <= 10; i++)
cout << myList << " ";
3. Define a two-dimensional array named temp of three rows and four columns of type int
such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 17, 5, 10, 6;
and the third row is initialized to 14, 13, 16, 20.
3.1 Write C++ statements to accomplish the following:
a. Output the contents of the first row and first column element of temp.
b. Output the contents of the first row and last column element of temp.
c. Output the contents of the last row and first column element of temp.
d. Output the contents of the last row and last column element of temp.
1
Abdullah Shbtat
4. What is the output of the following program?
#include <iostream>
using namespace std;
int main()
{
int j;
int one[5];
int two[10];
for (j = 0; j < 5; j++)
one[j] = 5 * j + 3;
cout << "One contains: ";
for (j = 0; j < 5; j++)
cout << one[j] << " ";
cout << endl;
for (j = 0; j < 5; j++)
{
two[j] = 2 * one[j] - 1;
two[j + 5] = one[4 - j] + two [j];
}
cout << "Two contains: ";
for (j = 0; j < 10; j++)
cout << two[j] << " ";
cout << endl;
return 0;
}
9. Write a C++ program to find the maximum and minimum value of an (one dimensional array
and two dimensional array) of type double.
2
Abdullah Shbtat
10. Write a C++ program to test the equality of two arrays of type char.
11. Write a C++ program to check an array of 20 components of type int, whether the sum of
first ten components is greater than last ten components or not. Display on the screen (The
sum of first ten components and the sum of the last ten components).
12. Write a C++ program to find the number of even and odd numbers in an array of type int.
(using while, do while and for loop)
13. Write a C++ program to find the number of even and odd numbers in an (two dimensional
array 5×6) of type double, using while loop.
14. Write a C++ program that declares an array alpha of 50 components of type double.
14.1 Initialize the array so that the first 25 components are equal to the square of the
index variable.
14.2 The last 25 components are equal to three times the index variable.
14.2 Output the array so that 10 elements per line are printed.
15. Write a C++ program that declares a (two dimensional array) matrix of 12 components of
type double.
15.1 Initialize the array so that the first row components are equal to the square of the
index variable.
15.2 The second row components are equal to three times the index variable.
15.3 The Third row components are equal to four times the index variable.
15.4 Output the array so that 4 elements per line are printed.
3
Abdullah Shbtat