Code Competitions

Coding competition

Monday, 13 May 2013

program to use pointer to display elements of 2-dimensional array

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,i,j,m,a[10][10],*p[10];
    clrscr();
  printf("enter the order of matrix ");
   scanf("%d%d",&m,&n);
   printf("\nenter the elements of matrix: ");
    p[0]=&a[0][0];
    //p[0]=t[0];
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>*(*(a+i)+j);
        }
    }
    //*p=&a[0][0];
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("  %d",*(*(p+i)+j));
        }
       printf("\n");
    }
    getch();
}

No comments:

Post a Comment