Assignment 2 Data Structures and Algorithms
Assignment 2 Data Structures and Algorithms
Assignment 2
ID: 4221382
Task I
Create ID array of size entered by the user, enter its number externally from user and print its
content in a readable way. In the previous array, sum a number of elements between two positions
Code:
#include <iostream>
#include <vector>
int main() {
int size;
vector<int> idArray(size);
}
cout << "ID Array: ";
int sum = 0;
sum += idArray[i];
cout << "Sum between positions " << start << " and " << end << ": " << sum << endl;
return 0;
Sample Output:
Enter 5 elements:
36915
ID Array: 3 6 9 1 5
Enter starting and ending positions to sum: 1 3
Task 2
Create 2D array of size entered by the user, enter its number externally from user and print its
content in a readable way, print the sum of each column and for each row.
Code:
#include <iostream>
#include <vector>
int main() {
cout << "Enter number of rows and columns for 2D array: ";
int rowSum = 0;
rowSum += array[i][j];
cout << "Row " << i << ": " << rowSum << endl;
int colSum = 0;
colSum += array[i][j];
cout << "Column " << j << ": " << colSum << endl;
return 0;
}
Sample Output:
123
456
2D Array:
123
456
Row Sums:
Row 0: 6
Row 1: 15
Column Sums:
Column 0: 5
Column 1: 7
Column 2: 9