Lab 7
Lab 7
int main(){
int i, x[10];
srand(time(0));
for (i = 0 ; i < 10 ; i++)
x[i] = rand() % 10;
for (i = 0 ; i < 10 ; i++)
cout << x[i] << ' ';
cout << '\n';
return 0;
}
Task 0: Type this and execute, if any student has any issues please discuss.
Task 1: Declare another array of same size, initialize the second array in similar way, you may write
another loop or do initialization in a separate loop. Next, run a loop and print corresponding elements of
both arrays.
Sample Run:
2 4
3 1
6 6
...
Task 2: Revise task 1, While printing, compare and print message in front of each pair of elements
"First", "Second" and "Equal". Print "First", if element of the first array is larger. Print "Second", if
element of the second array is larger. Print "Equal", if both elements are equal.
Sample Run:
2 4 Second
3 1 First
7 3 First
4 4 Equal
...
Task 3: Revise task 1, declare another array of same size. Add sum of corresponding elements in the
third array. Next print corresponding element of first array, second array and sum in a single line.
Sample Run:
2 4 6
3 1 4
7 3 10
4 4 8
...
Task 4: Revise task 1, find maximum from both arrays. Print the maximum element of both arrays.
Compare them and print "Array 1 has maximum element larger than Array 2" or vice versa.
Task 5: Revise task 0, run two more loops. In first loop print even elements of the array, in second loop
print odd elements of the array.
Task 6: Revise task 0, check elements are in order or not. By order means that elements on left side are
smaller than elements on right side, for every element.