How to display 2-d array in C programming

Discussion in 'C' started by C-user, Oct 20, 2011.

  1. C-user

    C-user New Member

    Joined:
    Oct 19, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Could somebody kindly show me how to make a C coding using a 2-d array that display output like this:

    Name....Age
    ..A.........8
    ..B........10
     
  2. tehniyat

    tehniyat New Member

    Joined:
    Oct 28, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int arr[26][2],i,j,n=8,c=65;
    clrscr();
    printf("Name..................Age");
    for(i=0;i<26;i++)
    {
    for(j=0;j<1;j++)
    {
    printf("%c\t%d",n,c);
    }
    n=n+2;
    c=c+1;
    printf("\n");
    }

    getch();
    }
     
  3. johnBMitchell

    johnBMitchell New Member

    Joined:
    Feb 17, 2011
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    CA, USA
    Home Page:
    http://www.spinxwebdesign.com/
    Below given example is the 2-D array with output.

    Code:
    #include <stdio.h>
    #include <conio.h>
    void main()
    {
    	int a[3][3], i, j;
    	clrscr();
    	printf("\n\t Enter matrix of 3*3 : ");
    	for(i=0; i<3; i++)
    	{
    		for(j=0; j<3; j++)
    		{
    		scanf("%d",&a[i][j]);  //read 3*3 array
    		}
    	}
    	printf("\n\t Matrix is : \n");
    	for(i=0; i<3; i++)
    	{
    		for(j=0; j<3; j++)
    		{
    		printf("\t %d",a[i][j]);  //print 3*3 array
    		}
    	   printf("\n");
    	}
    	getch();
    }
    
    Output:

    Enter matrix of 3*3: 3 4 5 6 7 2 1 2 3

    Matrix is:
    3 4 5
    6 7 2
    1 2 3_
     
  4. Mahmood Tahir

    Mahmood Tahir New Member

    Joined:
    Oct 30, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice