Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void ArrayCreate(double*** arr, int Dim1, int Dim2);
- //double** func(int Dim1, int Dim2);
- int main() {
- double** a;
- int n = 3, m = 3;
- a = (double**)calloc(n, sizeof(double*));
- for (int i = 0; i < n; i++) a[i] = (double*)calloc(m, sizeof(double));
- a[0][2] = 3.14;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) a[i][j] = 3.14 + 2.0 * i;
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) printf("%1.9f ", a[i][j]);
- printf("\n");
- }
- for (int i = 0; i < n; i++) free(a[i]);
- free(a);
- double** b;
- ArrayCreate(&b, n, m);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) b[i][j] = 3.14 + 2.0 * i;
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) printf("%1.9f ", b[i][j]);
- printf("\n");
- }
- for (int i = 0; i < n; i++) free(b[i]);
- free(b);
- /*double** c = func(n, m);
- c[0][2] = 3.14;
- printf("%f", c[0][2]);*/
- }
- /*double** func(int Dim1, int Dim2) {
- double** arr = (double**)calloc(Dim1, sizeof(double*));
- for (int i = 0; i < Dim1; i++) arr[i] = (double*)calloc(Dim2, sizeof(double));
- return arr;
- }
- */
- void ArrayCreate(double*** arr, int Dim1, int Dim2) {
- *arr = (double**)calloc(Dim1, sizeof(double*));
- for (int i = 0; i < Dim1; i++) (*arr)[i] = (double*)calloc(Dim2, sizeof(double));
- }
Add Comment
Please, Sign In to add comment