Home

A program to pass two dimensional array to a function

C Programming Language 080

Program

#include <stdio.h>

void array(int[][100], int, int);
void main()
{
    int a[100][100], m, n, i, j;
    printf("Enter order m,n [m x n]: ");
    scanf("%d %d", &m, &n);

    printf("Enter elements:\n");
    for (i = 0; i < m; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }

    array(a, m, n);
    printf("\n");
}

void array(int c[][100], int p, int q)
{
    int i, j;
    printf("Passed array...\n");

    for (i = 0; i < p; i++)
    {
        for (j = 0; j < q; j++)
        {
            printf("%d\t", c[i][j]);
        }
        printf("\n");
    }
}

Result

Enter order m,n [m x n]: 2 2
Enter elements:
1 2
3 4
Passed array...
1       2
3       4


Last Updated on

Next Post: Rules vs Guidelines →

Comments