0% found this document useful (0 votes)
89 views2 pages

FCP Tasks Arrays

This document discusses writing code to perform various operations on arrays and matrices, including sorting, merging, filling, and decomposing arrays. It provides 10 tasks involving writing code to: 1) Sort an array 2) Merge two sorted arrays 3) Create an inversion array for a given array 4) Fill a 2D array with consecutive numbers in different directions across columns 5) Fill a 2D array with consecutive numbers in diagonals 6) Fill a 2D array in a spiral pattern 7) Sort each row of a 2D array separately 8) Find the LU decomposition of a square matrix 9) Solve a system of linear equations with Gaussian elimination 10) Perform the above tasks using std

Uploaded by

JuliaZiębińska
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views2 pages

FCP Tasks Arrays

This document discusses writing code to perform various operations on arrays and matrices, including sorting, merging, filling, and decomposing arrays. It provides 10 tasks involving writing code to: 1) Sort an array 2) Merge two sorted arrays 3) Create an inversion array for a given array 4) Fill a 2D array with consecutive numbers in different directions across columns 5) Fill a 2D array with consecutive numbers in diagonals 6) Fill a 2D array in a spiral pattern 7) Sort each row of a 2D array separately 8) Find the LU decomposition of a square matrix 9) Solve a system of linear equations with Gaussian elimination 10) Perform the above tasks using std

Uploaded by

JuliaZiębińska
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Fundamentals of Computer Programming

Arrays

Constants const int N, const int W, const int K have values known in compilation time.

1. Write a piece of code that sorts an array 1 2 4 7


(whose size is const int N). 3 5 8 11
6 9 12 15
2. Write a piece of code that merges two sorted
10 13 16 18
arrays (with sizes const int M and const int
14 17 19 20
N) of double precision floating point numbers
into one array (whose size is M + N). You may 6. Write a piece of code that fills a two-
not use any sorting algorithm. Example: dimensional array with const int W rows and
const int K columns with consecutive num-
2 6 9 10 12 15
bers in a spiral.
1 3 7 8 20
Example for W == 5 and K == 4:
result:
1 2 3 4
1 2 3 6 7 8 9 10 12 15 20 14 15 16 5
13 20 17 6
3. Write a piece of code that fills an inversion ar-
12 19 18 7
ray for array arr. An inversion array has the
11 10 9 8
same length as array arr. An ith cell of an in-
version array holds a number of elements with 7. Write a piece of code that sorts separately each
indices 0, 1, . . . , i in array arr less then the ith row of a two-dimensional array with const int
item of array arr. W rows and const int K columns.
Example: array arr Example for W == 5 and K == 4:
5 8 19 4 2 5 1 5 3 12 6 11 initial array:
inversion array for arr
1 2 3 4
0 1 2 0 0 2 0 3 2 8 7 9
14 15 16 5
4. Write a piece of code that fills a two- 13 20 17 6
dimensional array with const int W rows 12 19 18 7
and const int K columns with consecutive 11 10 9 8
numbers downwards in the zeroth column,
upwards in the first column etc. sorted array:
Example for W == 5 and K == 4: 1 2 3 4
1 10 11 20 5 14 15 16
2 9 12 19 6 13 17 20
3 8 13 18 7 12 18 19
4 7 14 17 8 9 10 11
5 6 15 16 8. Write a piece of code that finds the LU de-
5. Write a piece of code that fills a two- composition of a square array with const int
dimensional array with const int W rows and N rows.
const int K columns with consecutive num- 9. Write a piece of code that solves a system
bers in diagonals. of const int N linear equations with Gaussian
Example for W == 5 and K == 4: elimination algorithm.

1
10. Solve above tasks for std :: vectors instead of
arrays.

You might also like