Question

In: Computer Science

C++ How do you make a 2d array with a user input. For example, the row...

C++ How do you make a 2d array with a user input. For example, the row and columns of the 2d array will be the same so the program can create a square matrix.

Solutions

Expert Solution

Code

#include<iostream>

using namespace std;

int main()
{
   int **array;
   int size;

   cout<<"Enter the size of the mateix: ";
   cin>>size;

   array=new int*[size];
  
   for(int i=0;i<size;i++)
   {
       array[i]=new int[size];
   }

   for(int i=0;i<size;i++)
   {
       for(int j=0;j<size;j++)
       {
           cout<<"Enter the ("<<i<<", "<<j<<") the value in matrix: ";
           cin>>array[i][j];
       }
   }
   cout<<"\n\nMatrix is : "<<endl;
   for(int i=0;i<size;i++)
   {
       for(int j=0;j<size;j++)
       {
           cout<<array[i][j]<<" ";
       }
       cout<<endl;
   }
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

How to make a 2D array Tic Tac Toe game in C?
How to make a 2D array Tic Tac Toe game in C?
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input #...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input # of rows: 2 Input Row 1: 9 8 7 6 3 2 1 5 4 Input Row 2: 1 2 4 3 5 6 9 8 7 Output 1,2,3,4,5,6,7,8,9 1,2,3,4,5,6,7,8,9
write a function declaration for a 2d array where each row size is 8 and the...
write a function declaration for a 2d array where each row size is 8 and the function does not return anything.
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. IN C Program.
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. Need it in 10 minutes, please.
Which row has the largest sum? Write a method that takes a 2D int array and...
Which row has the largest sum? Write a method that takes a 2D int array and prints: of The index of the row that has the largest sum The sum of elements in that row java
In c++, Can anyone make these code int user input as user have to put all...
In c++, Can anyone make these code int user input as user have to put all the amount. int main()    {        Polygon p1(3,4,4.5,5.5);        Polygon p2(4,4,5.5,6.5);        Polygon p3(5,4,6.5,7.5);               cout<<"Area of Polygon#1:"<<p1.getArea()<<endl;        cout<<"Perimeter of Polygon#1:"<<p1.getPerimeter()<<endl;               cout<<"\nArea of Polygon#2:"<<p2.getArea()<<endl;        cout<<"Perimeter of Polygon#2:"<<p2.getPerimeter()<<endl;               cout<<"\nArea of Polygon#3:"<<p3.getArea()<<endl;        cout<<"Perimeter of Polygon#3:"<<p3.getPerimeter()<<endl;                         return 0;     ...
few problems example of array and 2d array and the solution code in java language. I...
few problems example of array and 2d array and the solution code in java language. I am new to java and trying to learn this chapter and it is kinda hard for me to understand.
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and...
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and returns only the odd index entries. Do this by first setting the even entries to 0, and then removing the 0 entries by using a logical array. The first line of your code should read function p = ReturnOddEntries(p) For example, if you run in the command window p = ReturnOddEntries([1.2 7.1 8.4 -42 100.1 7 -2 4 6]), then you should get p...
1. Make your own example of a 5-by-3 matrix that is in echelon row but do...
1. Make your own example of a 5-by-3 matrix that is in echelon row but do not reduce row echelon form. 2. Repeat for a 2-by-6 matrix 3. Make a 4-by-4 rref matrix whose first column contains only zeros
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT