Ip 1
Ip 1
Ip 1
UNITY UNIVERSITY
DEPARTIMENTS OF COMPUTER SCIENCE
NAME ID
SUBMITTED TO:TESHOME M.
SUBMITTED DATE
1. Write a C++ program to find the largest element of a given array of integers
#include <iostream>
using namespace std;
int main() {
int arr[] = {5, 2, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int arr[] = {5, 2, 9, 1, 7};
findLargestThree(arr, size);
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int arr[] = {5, 2, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);
int k = 3;
return 0;
}
4. Write a C++ program to find the most occurring element in an array of integers
#include <iostream>
#include <unordered_map>
using namespace std;
return mostOccurring;
}
int main() {
int arr[] = {5, 2, 9, 1, 7, 5};
int size = sizeof(arr) / sizeof(arr[0]);
cout << "Most occurring element: " << mostOccurring << endl;
return 0;
}
5. Write a C++ program to update every array element by multiplication of next and
previous values of a given array of integers
#include <iostream>
using namespace std;
int main() {
int arr[] = {5, 2, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);
updateArray(arr, size);
return 0;
}
6. Write a C++ program to find the two repeating elements in a given array of
integers.
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
int arr[] = {5, 2, 9, 1, 7, 2, 5};
int size = sizeof(arr) / sizeof(arr[0]);
findRepeatingElements(arr, size);
return 0;
}
0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int matrix[MAX_SIZE][MAX_SIZE];
int transpose[MAX_SIZE][MAX_SIZE];
int m, n;
char choice;
cout << "Enter number of rows and columns (m and n): ";
cin >> m >> n;
do {
cout << "Menu:" << endl;
cout << "a. To input elements into matrix of size m x n" << endl;
cout << "b. To display elements of matrix of size m x n" << endl;
cout << "c. Sum of all elements of matrix of size m x n" << endl;
cout << "d. To display row-wise sum of matrix of size m x n" << endl;
cout << "e. To display column-wise sum of matrix of size m x n" << endl;
cout << "f. To create transpose of matrix B of size n x m" << endl;
cout << "x. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 'a':
inputMatrix(matrix, m, n);
break;
case 'b':
displayMatrix(matrix, m, n);
break;
case 'c': {
int sum = sumOfElements(matrix, m, n);
cout << "Sum of elements: " << sum << endl;
break;
}
case 'd':
displayRowWiseSum(matrix,m, n);
break;
case 'e':
displayColumnWiseSum(matrix, m, n);
break;
case 'f':
createTranspose(matrix, m, n, transpose);
displayMatrix(transpose, n, m);
break;
case 'x':
cout << "Exiting program..." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
return 0;
}
e.g.,
23150 23150
71531 1531
01501 01
34915 5
#include <iostream>
using namespace std;
int main() {
int matrixA[MAX_SIZE][MAX_SIZE];
int matrixB[MAX_SIZE][MAX_SIZE];
int result[MAX_SIZE][MAX_SIZE];
int m, l, n;
cout << "Enter number of rows and columns for matrix A (m and l): ";
cin >> m >> l;
cout << "Enter number of rows and columns for matrix B (l and n): ";
cin >> l >> n;
if (l != l) {
cout << "Invalid input. Number of columns in matrix A should be equal to
number of rows in matrix B." << endl;
return 0;
}
inputMatrix(matrixA, m, l);
inputMatrix(matrixB, l, n);
return 0;
}
#include <iostream>
using namespace std;
int main() {
int matrixA[MAX_SIZE][MAX_SIZE];
int matrixB[MAX_SIZE][MAX_SIZE];
int result[MAX_SIZE][MAX_SIZE];
int m, l, n;
cout << "Enter number of rows and columns for matrix A (m and l): ";
cin >> m >> l;
cout << "Enter number of rows and columns for matrix B (l and n): ";
cin >> l >> n;
if (l != l) {
cout << "Invalid input. Number of columns in matrix A should be equal to
number of rows in matrix B." << endl;
return 0;
}
inputMatrix(matrixA, m, l);
inputMatrix(matrixB, l, n);