Access over 20 million homework & study documents

A matrix is a 2 D array Write a program thatask for the number

Content type
User Generated
Rating
Showing Page:
1/4
A matrix is a 2-D array.
Write a program that:
ask for the number of row and number of column for the
matrix M
asks the user to enter the value of each cell of the matrix
(for example M[i][j])
displays 2*M (each value in a cell is multiplied by 2 and
displayed.
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
class Mat {
void main()
{
int row, col, i, j;
cout<< \"enter number of rows: \";
Scanner p = new Scanner(System.in);
row = p.nextInt();
System.out.println(\"enter number of column\");
col = p.nextInt();
int a[i][j] = new int[row][col];
System.out.println(\"enter the value of each cell\");
for (i = 0; i<row; i++)
for (j = 0; j<col; j++)
a[i][j] = p.nextInt();
for (i = 0; i<row; i++)
for (j = 0; j<col; j++)
System.out.println(2 * a[i][j]);
}
}
Someone fix the code for me please

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/4
Solution
Mat.java
import java.util.Scanner;
public class Mat {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int row, col, i, j;
Scanner p = new Scanner(System.in);
System.out.println(\"enter number of rows\");
row = p.nextInt();
System.out.println(\"enter number of columns\");
col = p.nextInt();
int a[][] = new int[row][col];
System.out.println(\"enter the value of each cell\");
for (i = 0; i<row; i++)
for (j = 0; j<col; j++)
a[i][j] = p.nextInt();

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/4

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 4 pages?
Access Now
Unformatted Attachment Preview
A matrix is a 2-D array. Write a program that: ask for the number of row and number of column for the matrix M asks the user to enter the value of each cell of the matrix (for example M[i][j]) displays 2*M (each value in a cell is multiplied by 2 and displayed. #include #include #include #include class Mat { void main() { int row, col, i, j; cout ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Great study resource, helped me a lot.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4