A matrix (2-dimensional) contains rows numbered from 2 to 9, and columns numbered from 1 to 100. In each cell of the matrix is a number equal to (row + col – row*col) (where row, col are the row and column numbers). Write a summation that will generate the total value of all cells in the matrix. (It is not necessary to calculate the total.)
*Note: Since no particular language was mentioned, I have used C++
#include<iostream>
using namespace std;
int main()
{
int sum=0;
int rows,cols;
while(1){
cout<<"Enter number of rows: ";
cin>>rows;
if(rows>1&&rows<10)
break;
else
cout<<"Wrong input! Please try again!";
}
while(1){
cout<<"Enter number of columns: ";
cin>>cols;
if(cols>0&&cols<101)
break;
else
cout<<"Wrong input! Please try again!";
}
int arr[rows][cols];
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
arr[i][j]=i+j-i*j;
sum=sum+arr[i][j];
}
}
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<"sum :"<<sum;
}
A matrix (2-dimensional) contains rows numbered from 2 to 9, and columns numbered from 1 to...
1) Define a 2 dimensional arrays of doubles (3 rows by 3 columns) and 2) Read values from the user. 3) Print the numbers entered by the user in row major order 4) Print the numbers entered by the user in column major order import java.util.*; public class XXX_Chapter83 { public static void main(String[] args) { //creates array and stores values with input from user printArrayRowMajor (board); printArrayColumnMajor (board); } public static void printArrayRowMajor (int [] [] board) { //prints...
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...
Write a program that reads a matrix from the keyboard and displays the summations of all its rows on the screen. The size of matrix (i.e. the number of rows and columns) as well as its elements are read from the keyboard. A sample execution of this program is illustrated below: Enter the number of rows of the matrix: 3 Enter the number of columns of the matrix: 4 Enter the element at row 1 and chd umn 1: 1...
Given a matrix with m rows and n columns, m adjacent numbers are chosen from m rows, where two numbers are adjacent to each other if they are directly connected vertically or diagonally and only one number is taken from one row. Design a dynamic programming algorithm to find the smallest sum of these m numbers. For example, given a 3 by 3 matrix 1 2 3 4 5 6 7 0 2 The sum of three numbers 1, 4,...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e. a two-dimensional array), number of rows and number of columns as input and prints the matrix after rotating it 90 degrees clockwise. Example: void rotate-matrix (int* matrix, int row, int column) Inputs: row 4, column-6 and the pointer to the matrix below: 2 3 6 5 8 0 Output:
A matrix named mach contains 3 columns of data
concerning the energy output of several machines. The first column
contains an ID code for a specific machine, the second column
contains the total amount of energy produced by that machine in
calories, and the third column contains the amount of time required
by that machine to produce the energy listed in column 2 in
hours.
Write a MATLAB program that will:
a) Request the user for the matrix mach.
b)...
9. Lo Shu Magic Square The Lo Shu Magic Square is a grid with three rows and three columns that has the following properties: The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown in the following figure · 15 4 9 2-15 3 5 7-15 81 615 15 15 15 15 Write a program that simulates a magic square using...
Enter T or F depending on whether the statement is true or false. (Only ONE attempt allowed.) (You must enter Tor F -- True and False will not work.)_______ 1. A matrix with dimensions m by n, where m > n, has fewer rows than columns._______ 2. The 3rd row, 4th column entry of a matrix is below and to the right of the 2nd row, 3rd column entry.
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...