Solved programming problem

How to Scan and print 2D array with pointer in C.

Source code

#include<stdio.h>

int main()

{

    int n,i,j;

    int flag=0;

    int *ptr[100][100]; ///Declaring 2D pointer variable

    printf("Please Enter the Array row or column size: ");

    scanf("%d",&n);

    printf("Please Enter Elements: 
",n);

    for(i=0; i<n; i++)

    {

        for(j=0; j<n; j++)

        {

            scanf("%d",(*(ptr+i)+j)); ///scan

        }

    }

    printf("
Your Array: 
");

    for(i=0; i<n; i++)

    {

        for(j=0; j<n; j++)

        {

            printf("%d ",*(*(ptr+i)+j)); ///print

        }

        printf("
");

    }

    return 0;

}

Output

Please Enter the Array row or column size: 3
Please Enter Elements:
1 2  3
4 5 6
7 8 9

Your Array:
1 2 3
4 5 6
7 8 9

Join the discussion

Add your comment