Created
October 14, 2018 13:16
-
-
Save rmuhamedgaliev/98652cb533fc96843bfdd641edfe3aa1 to your computer and use it in GitHub Desktop.
dynamicheskiy_massiv.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <unistd.h> | |
#include <cstdio> | |
using namespace std; | |
int** create2DArray(unsigned height, unsigned width) | |
{ | |
int** array2D = 0; | |
array2D = new int*[height]; | |
for (int h = 0; h < height; h++) | |
{ | |
array2D[h] = new int[width]; | |
for (int w = 0; w < width; w++) | |
{ | |
// fill in some initial values | |
// (filling in zeros would be more logic, but this is just for the example) | |
array2D[h][w] = w + width * h; | |
} | |
} | |
return array2D; | |
} | |
void arrayPrinter(int **my2DArray, int n, int k) { | |
// print contents of the array2D | |
printf("Array contents: \n"); | |
for (int h = 0; h < n; h++) | |
{ | |
for (int w = 0; w < k; w++) | |
{ | |
printf("%i \t", my2DArray[h][w]); | |
} | |
printf("\n"); | |
} | |
} | |
int main () | |
{ | |
int n, k; | |
cout << "N="; //ввод количества строк | |
cin >> n; | |
cout << "M="; //ввод количества столбцов | |
cin >> k; | |
int** a = new int*[n]; | |
for(int i = 0; i < n; ++i) | |
a[i] = new int[k]; | |
for (int h = 0; h < n; h++) | |
{ | |
a[h] = new int[k]; | |
for (int w = 0; w < k; w++) | |
{ | |
a[h][w] = w + k * h; | |
} | |
} | |
for (int h = 0; h < n; h++) | |
{ | |
for (int w = 0; w < k; w++) | |
{ | |
printf("%i \t", a[h][w]); | |
} | |
printf("\n"); | |
} | |
// printf("Creating a 2D array2D\n"); | |
// printf("\n"); | |
// int** my2DArray = create2DArray(n, k); | |
// arrayPrinter(my2DArray, n, k); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <unistd.h> | |
#include <cstdio> | |
using namespace std; | |
int** create2DArray(unsigned height, unsigned width) | |
{ | |
int** array2D = 0; | |
array2D = new int*[height]; | |
for (int h = 0; h < height; h++) | |
{ | |
array2D[h] = new int[width]; | |
for (int w = 0; w < width; w++) | |
{ | |
// fill in some initial values | |
// (filling in zeros would be more logic, but this is just for the example) | |
array2D[h][w] = w + width * h; | |
} | |
} | |
return array2D; | |
} | |
void arrayPrinter(int **my2DArray, int n, int k) { | |
// print contents of the array2D | |
printf("Array contents: \n"); | |
for (int h = 0; h < n; h++) | |
{ | |
for (int w = 0; w < k; w++) | |
{ | |
printf("%i \t", my2DArray[h][w]); | |
} | |
printf("\n"); | |
} | |
} | |
int main () | |
{ | |
int n, k; | |
cout << "N="; //ввод количества строк | |
cin >> n; | |
cout << "M="; //ввод количества столбцов | |
cin >> k; | |
printf("Creating a 2D array2D\n"); | |
printf("\n"); | |
int** my2DArray = create2DArray(n, k); | |
arrayPrinter(my2DArray, n, k); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment