Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
894 B
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

int * array2D(int r, int c);

int main(void)
{
    int stu_id = 70357003;

    int row, column;
    printf("Enter the size of row: ");
    scanf("%d", &row);
    printf("Enter the size of column: ");
    scanf("%d", &column);

    int *ptr;
    ptr = array2D(row, column);

    for(int i = 0; i < row; i++){
        for(int j = 0; j < column; j++){
            printf("Array[%d][%d] = %d\n", i, j, *(ptr + i + j));
        }
    }

    printf("\n\nStudent ID: %d\n\n", stu_id);
    return 0;
}

int * array2D(int r, int c){
    static int matrix_2d[100][100];
    int element;
    printf("Please enter the elements row-by-row:\n");

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            scanf("%d", &element);
            matrix_2d[i][j] = element;
        }
    }
    return matrix_2d;
}