Lab 01 - Arrays
Lab 01 - Arrays
Lab 01 - Arrays
Exercises/Tasks:
1. Write a program to copy the elements of one array into another array but in
reverse order. For example, if the first array contains the values 1, 2, 3, 4, 5
then the second array should contain the values (after copying from the first
array) 5, 4, 3, 2, 1.
2. Create a program that involves copying elements from two different arrays into a
third array.
3. Write a program to count (and print) the number of duplicate values in an array.
You can store the fixed (hard-coded) values in the array. Then print those array
values. Finally, count and print the number of duplicate values.
4. Write a program that removes the duplicate values from an array. First print the
original array (you can store the hard-coded values). Then, remove the duplicate
values from that array. Finally, print the new array (obtained after removing the
duplicate values), and print the sizes of both the original array and the new array.
5. Write a program to count (and print) the frequency of each element of the array
(means, how many times each element occurs in the array). You can store the
fixed (hard-coded) values in the array. Then print those array values. Finally,
count and print the frequency of each element.
6. Write a program that checks if a 2D array is row-magic (which means that every
row has the same row sum). If the sum of each of the rows in the entire 2D array
is the same, print “Row Magic” else print “Array is not Row-Magic”. First, print the
original array elements and then check (and print) if the array is Row Magic or
not
7. Write a program that flips a 2D array horizontally. First, print the original array
and then print the flipped version of that array.
Sample Output:
Original array values are:
3 7 2
8 4 1
5 9 6
8. Write a program that flips a 2D array vertically. First, print the original array and
then print the flipped version of that array.
Sample Output:
Original array values are:
3 7 2
8 4 1
5 9 6