
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Write a
Expert Solution

Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
Write a program in C++ which will read the elements of a sparse matrixfrom the keyboard and store them in a two-dimensional array in theform of a triplet.
Example: Consider a 4x4 sparse matrix0 0 0 28 0 0 00 5 0 00 0 4 0
Triplet (3 x4)Row 0 1 2 3Column 3 0 1 2Value 2 8 5 4
Also, do the same program in reverse (i.e. the triplet is given and yourprogram needs to print the corresponding sparse matrix.)
arrow_forward
Write a program in c using to read an array of 10 integers. Your program should accept only numbers from 3 to 8 as input.
Add 2 to elements at odd indexes and subtract 1 from elements at even indexes
Convert this 1D array into 2D array of size 2x5 and print the transpose of this 2D array on console window.
arrow_forward
Write a C Program that reads two matrices of integers. It then generates the sum and difference of the two matrices.
The sum of the two matrices of the same size is a matrix with elements that are the sums of the corresponding elements of the two given matrices. Addition is not defined for matrices of different sizes.
If A and B are matrices of the same size, then we define subtraction as follows: A – B = A + (-B). Thus, to subtract matrix B from matrix A, we simply subtract corresponding elements.
Note: Use array function
arrow_forward
Write a C program that reads two matrices of integers. It then generates the sum and difference of the two matrices.
The sum of the two matrices of the same size is a matrix with elements that are the sums of the corresponding elements of the two given matrices. Addition is not defined for matrices of different sizes.
If A and B are matrices of the same size, then we define subtraction as follows: A – B = A + (-B). Thus, to subtract matrix B from matrix A, we simply subtract corresponding elements.
arrow_forward
Write a C program that reads a matrix of n × m numbers, transpose the matrix, then print it out using pointers. (Do not use array subscript syntax such as a[0], a[i])
arrow_forward
Write a program that reads two matrices of integers. It then generates the sum, difference and productof the two matrices.The sum of the two matrices of the same size is a matrix with elements that are the sums of thecorresponding elements of the two given matrices. Addition is not defined for matrices of different sizes.If A and B are matrices of the same size, then we define subtraction as follows: A – B = A + (-B). Thus, tosubtract matrix B from matrix A, we simply subtract corresponding elements.To multiply a matrix by another matrix we need to do the "dot product" of rows and columns. The "DotProduct" is where we multiply matching members, then sum up:(1, 2, 3) • (7, 9, 11) = 1×7 + 2×9 + 3×11 = 58We match the 1st members (1 and 7), multiply them, likewise for the 2nd members (2 and 9) and the3rd members (3 and 11), and finally sum them up.
arrow_forward
Write a c++ program to declare an array of odd number of elements. Split it into the middle and store the elements in two different arrays. e.g.
Initial array:
22
58
19
87
15
72
9
1
37
After splitting:
22
58
19
87
15
72
9
1
37
As output, your code should print the original and the two split arrays, each element separated by the comma sign. Your code should be generic enough to also work for arrays with an even number of elements.
arrow_forward
Write a program in C that will find the largest number from a 4X4 matrix and divide each element of the odd columns of that matrix by that largest number and store in a new matrix then print the matrix. Take inputs from user. Use the following prototype:void normalizeMatrix(int rowSize, int colSize, float mat[rowSize][colSize])void printMatrix(int rowSize, int colSize, float mat[rowSize][colSize])
arrow_forward
Write a program in C++ which takes two 4 x 4 matrices as input from the user and displays the matrices in tabular form. Then ask user to make a choice:
1. Press 1 for matrix addition
2. Press 2 for matrix subtraction
3. Press 3 for matrix multiplication
4. Press 4 for matrix transpose
Use 2D arrays to save matrix values and use functions to perform addition, subtraction, multiplication and transpose.
arrow_forward
Write a program in C++ to add two Matrices user have to input number of rows and columns of matrices and then enter the elements of both the matrices, Store the input into a multidimensional array for each matrix and after that add corresponding elements of both the matrices and displaying them on screen.
arrow_forward
Write a Python function
def isSubArray(A,B)
which takes two arrays and returns True if the first array is a (contiguous) subarray of the second array, otherwise it returns False. You may solve this problem using recursion or iteration or a mixture of recursion and iteration.
For an array to be a subarray of another, it must occur entirely within the other one without other elements in between. For example:
[31,7,25] is a subarray of [10,20,26,31,7,25,40,9]
[26,31,25,40] is not a subarray of [10,20,26,31,7,25,40,9]
A good way of solving this problem is to make use of an auxiliary function that takes two arrays and returns True if the contents of the first array occur at the front of the second array, otherwise it returns False. Then, A is a subarray of B if it occurs at the front of B, or at the front of B[1:], or at the front of B[2:], etc. Note you should not use A == B for arrays.
arrow_forward
Write a program in C that prints a 10x10 matrix of random integers (0 - 10000) on screen.
arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning