i cannot get the logic of this thing...

i will input the number of rows

example "rows=5"

then

"input the numbers = 2 3 8 9 7"

what codes could i use???

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by VernonDozier

You can use this :

``````int row;
cin >> row;
int *arr = new int[ row ];
for( int i = 0; i < row; i++ )
cin >> arr[ i ];``````

But I think I don't understand you .

``````#include <iostream>
#include <iomanip>
using namespace std;
int main() {

int rows;
cout<< "put the number of rows here"" ";
cin >> rows;
cout<< "numbers here""\n ";
int *arr = new int[ rows ];
for( int i = 0; i < rows; i++ ){

cin >> arr[ i ];
}

int col;
cout<< "put the number of columns here"" ";
cin >> col;
cout<< "numbers here""\n ";
int *arra = new int[ col ];
for( int j = 0;j < col; j++ ){

cin >> arr[ i ];
}
cout << setw(5) <<  ;
return 0;
}``````

iwant now this to be like a multiplication table..hehehe

If this is a multiplication table, why do you want the user to input the cells? Values will be from 0 or 1 to numRows or numCols.

Regardless, you create a dynamic 2-D array like this:

``````int numRows, numCols;

cin >> numRows;
cin >> numCols;

int** arr = new int*[numRows];
for(int i = 0; i < numRows; i++)
{
arr[i] = new int[numCols];
}``````

Now the array is created. Fill in the values however you like.

Edited by VernonDozier: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.