Thread: array 2 dimension using pointer and function in c

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2020
    Posts
    5

    array 2 dimension using pointer and function in c

    i stuck with my code to change this code by using a pointer. mybe someone want to help me fixed it.

    this my code :
    Code:
    #include <stdio.h>
    #define size 100
    
    
    int array2d(int x[size][size], int a, int b)
    {
        int i, j;
        for (i = 0; i < a; i++)
        {
            for (j = 0; j < b; j++)
            {
                printf("%d ", x[i][j]);
            }
            printf("\n");
        }
    }
    int main()
    {
        int a, b;
        int x[size][size];
    
    
        printf("enter the size of array (row) & (column) : ");
        scanf("%d %d", &a, &b);
    
    
        printf("enter the number : ");
    
    
        for (int i = 0; i < a; i++) //reading input
        {
            for (int j = 0; j < b; j++)
            {
                scanf("%d", &x[i][j]);
            }
        }
    
    
        array2d(x, a, b);
    
    
        return 0;
    }
    please help me

    this code input :
    2 2

    and
    1 2 3 4

    should be an output :
    1 2
    3 4
    Last edited by riandrp; 12-05-2020 at 10:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-11-2011, 02:49 AM
  2. Double Pointer & Two Dimension Array ....
    By gokulvs in forum C Programming
    Replies: 7
    Last Post: 09-09-2009, 11:04 PM
  3. Passing a pointer to two-dimension array in a function
    By E_I_S in forum C++ Programming
    Replies: 11
    Last Post: 06-19-2008, 09:57 AM
  4. pass the pointer of a two dimension array to a function
    By SoFarAway in forum C Programming
    Replies: 8
    Last Post: 04-13-2005, 05:43 AM
  5. Passing a 2 dimension array to a function
    By Chuck in forum C++ Programming
    Replies: 8
    Last Post: 12-09-2002, 09:42 AM

Tags for this Thread