






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







1. Write down 2 C++ program to find the number of elements in array using sizeof operator. #include using namespace std; int main() { // Declare and initialize an array int arr[] = {10, 20, 30, 40, 50}; // Calculate the number of elements in the array int numElements = sizeof(arr) / sizeof(arr[0]); // Output the number of elements cout << "Number of elements in the array: " << numElements << endl; return 0; } 2.Write down a C++ program to find the multiplication of two matrices A[3][2] and B[2][3]. #include using namespace std; int main() { // Declare matrices A and B int A[3][2] = {{1, 2},
int B[2][3] = {{7, 8, 9}, {10, 11, 12}}; // Resultant matrix C will be of size 3x int C[3][3] = {0}; // Initialize to 0 // Matrix multiplication for (int i = 0; i < 3; i++) { // Rows of A for (int j = 0; j < 3; j++) { // Columns of B for (int k = 0; k < 2; k++) { // Columns of A / Rows of B C[i][j] += A[i][k] * B[k][j]; } } } // Display the resulting matrix C cout << "Resulting Matrix C (3x3):" << endl; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << C[i][j] << " "; } cout << endl; // New line for each row }
4.Write down a C++ program to find the subtraction and addition of two matrices A[3][3] and B[3][3]. #include using namespace std; int main() { // Declare and initialize matrices A and B int A[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int B[3][3] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}; // Declare matrices to store the result of addition and subtraction int sum[3][3]; int difference[3][3]; // Perform addition and subtraction for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sum[i][j] = A[i][j] + B[i][j]; // Add corresponding elements difference[i][j] = A[i][j] - B[i][j]; // Subtract corresponding elements } }
// Display the result of addition cout << "Matrix Addition (A + B):" << endl; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << sum[i][j] << " "; } cout << endl; } // Display the result of subtraction cout << "Matrix Subtraction (A - B):" << endl; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << difference[i][j] << " "; } cout << endl; } return 0; } 5.Write a C4+ program to find the transpose of a matrix A[3][3]. #include using namespace std;
for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << transpose[i][j] << " "; } cout << endl; } return 0; } 6 .Write a C++ program to read the temperature of the whole week in an array and then find the hottest day of the week. #include using namespace std; int main() { // Declare an array to store temperatures for 7 days float temperatures[7]; int hottestDay = 0; // To store the index of the hottest day float maxTemperature; // Input temperatures for each day of the week cout << "Enter the temperature for each day of the week:" << endl; for (int i = 0; i < 7; i++) { cout << "Day " << (i + 1) << ": "; cin >> temperatures[i];
// Assume the first day is the hottest initially maxTemperature = temperatures[0]; // Find the hottest day for (int i = 1; i < 7; i++) { if (temperatures[i] > maxTemperature) { maxTemperature = temperatures[i]; hottestDay = i; // Update the index of the hottest day } } // Display the hottest day and its temperature cout << "The hottest day of the week is Day " << (hottestDay + 1) << " with a temperature of " << maxTemperature << " degrees." << endl; return 0; } 7.Write a C++ program to read ten alphabets of English from the keyboard into a character type array and then sort them in descending order. #include using namespace std; int main() { // Declare an array to store 10 alphabets
return 0; } 8.Write a C++ program to find the sum of the values of a two dimensional array int Test[2] [3] and display the result on the screen. #include using namespace std; int main() { // Declare and initialize a 2x3 matrix int Test[2][3] = {{1, 2, 3}, {4, 5, 6}}; int sum = 0; // To store the sum of the elements // Calculate the sum of all elements in the matrix for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { sum += Test[i][j]; // Add each element to sum } } // Display the sum cout << "The sum of all elements in the matrix is: " << sum << endl; return 0;