Array Working Questions
Array Working Questions
i) Define the “A” array that stores 10 integer numbers (i.e. A[10]), then initialize the array
by using initialization method such that each element is 1-digit (0-9) number randomly.
iii) Select a number between 9 and 19 by using rand() function. Print it.
iv) Sum the items of the array. If the sum is less than selected number, print “Win”.
Otherwise, print “Lost”.
i) Define the “a” array that stores 10 integer numbers (i.e. a[10]), then initialize the array
by using initialization method such that each element is 1-digit (0-9) number randomly.
i) Define an array that stores 20 integer numbers (i.e., A[20]), then initialize the array
such that each element is 1-digit (0-9) number randomly.
ii) Print the array.
iii) Prompt a number from the user that is between 0 and 19. Print it.
iv) Check the array if it contains the number. If it is, print “the array contains the
number”, otherwise print “the array does not contain the number”.
𝑎𝑛 = 𝑎1 + 𝑑 ∗ (𝑛 − 1)
i) Define an array that stores 20 integer numbers (i.e., numbers[20]), then initialize the
array to zero.
ii) Print the array.
iii) Prompt the initial term 𝑎1 and common difference 𝑑. Print them.
iv) Calculate the the series and store it in array numbers.
v) Print the array.
vi) Test your program with 𝑎1 = 7 and 𝑑 = 4.
5) Reversing is an array operation that reverse all items of the array. An example is given below:
i) Define an array that stores 10 integer numbers (i.e., numbers[10]), then initialize and
print the array such that each element must be in the interval [7-24] number
randomly. Also, define integer arrays for reversed and difference arrays (i.e.,
reversed[10] and diff[10]) and initialize them to zero.
ii) The program must include the reverse function that receives the numbers and
reversed arrays. Then, reversing the original array and store it to reversed array.
(Prototype: void reverse(const int original[], int reversed[], int size)
iii) The program must include the difference function that receives the numbers, reversed,
and diff arrays. Then, take difference between original and reversed array and store
the difference in diff array. Return how many negative items in diff array (Prototype:
int difference(const int original[], const int reversed[], int diff[], int size).
iv) In main function, print the result, reversed and diff arrays.
6) Circular shifting is an array operation that shifts all items according to its operand. An example
is given below:
After circular shifting, the array becomes 5 4 1 6 9 2 8 3 7 10. The first 3 items according to its
operand are moved to the last 3 position.
Write a C program to operate circular shifting.
i) Define an array that stores 10 integer numbers (i.e., numbers[10]), then initialize and
print the array such that each element must be in the interval [47-94] number
randomly. Also, define an integer array for shifted array (i.e., shifted[10]) and
initialize it to zero.
ii) Select the operand between 1 and 4 by using rand function.
iii) The program must include the shift function that receives the operand, the numbers
and shifted arrays. Then, shifting the original array and store it to shifted array.
(Prototype: void shift(const int numbers[], int shifted[],int size, int operand)
iv) In main function, print numbers and shifted arrays.
Separate sorted array as taking the first 3 elements, then second 3 element ... as follows:
21 24 29 33 36
i) Define an array that stores 15 integer numbers (i.e., numbers[15]), then initialize the
array for the data given above by using the initializer list method. Also, define
integer array 3-median (i.e., med[5]) and initialize it to zero.
ii) The program must include the sort function that receives the numbers array. Then,
sorting the original array. (Prototype: void sort(int numbers[],int size)
iii) The program must include the median function that receives the numbers and med
arrays, then returns the mean of the 3-median of the array. In function, find 3-median
values of the array and store it to med array. Then calculate the mean of these five
values as follows: (Prototype: double median(const int numbers[], int med[],int
numbers_size, int med_size).
𝑚𝑒𝑑[0] + ⋯ + 𝑚𝑒𝑑[𝑛]
𝑚𝑒𝑎𝑛 =
𝑛
i) In main function, print the result, numbers, and med arrays.