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 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.
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
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...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
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
In C, build a connect 4 game with no GUI. Use a 2D array as the...
In C, build a connect 4 game with no GUI. Use a 2D array as the Data structure. First, build the skeleton of the game. Then, build the game. Some guidelines include... SKELETON: Connect Four is a game that alternates player 1 and player 2. You should keep track of whose turn it is next. Create functions: Initialization – print “Setting up the game”. Ask each player their name. Teardown – print “Destroying the game” Accept Input – accept a...
How do I convert the integers in my 2D array list to output decimals numbers? My...
How do I convert the integers in my 2D array list to output decimals numbers? My program works accepting regular integers, but crashes when decimals are entered into my 2D array list. Can someone improve it so it accepts decimal numbers? Here is my code: import javax.swing.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class TwoDimArray { private int numbers[][]; public TwoDimArray() { loadArray(); } public void loadArray() { /* //loadArray() method loads the users defined filename //@return returns the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT