Question

Write a program that reads a matrix from the keyboard and displays the summations of all its rows on the screen. The size of

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>

using namespace std;

int main()
{
int r,c;
  
cout<<"Enter the number of rows of the matrix: ";
cin>>r;
cout<<"Enter the number of colums of the matrix: ";
cin>>c;
  
int userMatrix[r][c];
  
for(int i =0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"Enter the element at row "<<(i+1)<<" and colum "<<(j+1)<<": ";
cin>>userMatrix[i][j];
}
  
}
  
for(int i =0;i<r;i++)
{
int sum = 0;
for(int j=0;j<c;j++)
{
sum = sum + userMatrix[i][j];
}
  
cout<<"The sum of elements in row "<<i<<" is: "<<sum<<endl;
}
return 0;
}

Output:

Enter the number of rows of the matrix: 3 Enter the number of colums of the matrix: 4 Enter the element at row 1 and colum 1:

Add a comment
Know the answer?
Add Answer to:
Write a program that reads a matrix from the keyboard and displays the summations of all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program that calculates the sum of a variable sized matrix using a two...

    Write a Java program that calculates the sum of a variable sized matrix using a two dimensional array. (ArraySum.java) The user should provide the number of rows and columns Test multiple user inputs (3 times 2, 4 times 4, 6 times 2, etc) A sum should be created for each row, each column, and the total for the matrix Ex.: How big would you like your matrix? Rows - ? 3 Columns -? 2 Please enter your row 1? Column...

  • 47. For a matrix A(:, m:n) refers to _ a. Refers to the elements in all...

    47. For a matrix A(:, m:n) refers to _ a. Refers to the elements in all the rows of column n of the matrix A. b. Refers to the elements in all the rows between columns m and n of the matrix A. c. Refers to the elements in all the columns between rows m and n of the matrix A. d. Refers to the elements in all the columns of row n of the matrix A. 48. What does...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8...

    Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9 ) ? = ( 2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22) ℎ = (4 9 12 15) b. Add suitable lines of codes to the M-file to do the following. Each of the following points should be coded in only...

  • on MathCad 1. Define a matrix PQ. component by component, using matrix subscripts, that satisfies the...

    on MathCad 1. Define a matrix PQ. component by component, using matrix subscripts, that satisfies the following: Matrix has 2 rows and 4 columns Each matrix element is equal to that element's column number plus its row number (assuming the Mathcad default of columns and rows start counting at the number zero) Show the resulting matrix

  • Problem 5 Create the following matrix by typing elements explicitly one command. Do not type individual...

    Problem 5 Create the following matrix by typing elements explicitly one command. Do not type individual 0 00 0 0 o o 0 0 0 0 0 1 2 3 F=0 01 10 20 0 0 2 8 26 0 0 3 6 32 E 0 045 6 0 0 7 8 9 Problem 6 Create two row vectors: a -4 10 0.5 1.8 -2.3 7, b [0.7 9 -53-0.6 12 (a) Use the two vectors in a MATLAB command...

  • (Markov matrix) An n by n matrix is called a positive Markov matrix if each element...

    (Markov matrix) An n by n matrix is called a positive Markov matrix if each element is positive and the sum of the elements in each column is 1. Write the following function to check whether a matrix is a Markov matrix: def isMarkovMatrix(m): Write a test program that prompts the user to enter a 3 by 3 matrix of numbers and tests whether it is a Markov matrix. Note that the matrix is entered by rows and the numbers...

  • JAVA Write a method that returns the sum of all the elements in a specified column...

    JAVA Write a method that returns the sum of all the elements in a specified column in a matrix using the following header: public static double sumColumn(double [][] m, int columnIndex) Write another method that returns the sum of all the elements in a specified row in a matrix using the following header: public static double sumRow( double [][] m, int rowIndex) Write a test program that reads a 3-by-4 matrix and displays the sum of each column and sum...

  • using matlab Create the following matrix B. [18 17 16 15 14 13] 12 11 10...

    using matlab Create the following matrix B. [18 17 16 15 14 13] 12 11 10 9 8 7 6 5 4 3 2 1 Use the matrix B to: (a) Create a six-element column vector named va that contains the elements of the second and fifth columns of B. (6) Create a seven-element column vector named vb that contains elements 3 through 6 of the third row of B and the elements of the second column of B. Create...

  • 1. Write a program that reads a sequence of numbers from the keyboard, and displays the...

    1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT