C program to insert elements in 2D-Array.


                                           Two dimensional array is the collection of rows and column. It collect the data into the table form. It used when we need to store data in form of table. In which it store the data the form of m*n where m is no. of rows and n is no of column. The first element is store on the row index 0 and column index 0 (A[0][0] ). Syntax of two dimensional  array is as follow :

                               Type <Array_name>[<No_of_rows>][No._of_column];

                               int A[3][3];

C program to insert value in array by user.

#include<stdio.h>
void main()
{
       int i,j,r,c;
       int A[10][10];
       clrscr();

       printf("Enter no. of rows : ");
       scanf("%d",&r);

       printf("Enter no. of column : ");
       scanf("%d",&c);

       printf("Enter element in 2D array : \n");
       for(i=0;i<r;i++)
       {
            for(j=0;j<c;j++)
            {
             printf("Element at A[ %d ][ %d ] : ",i,j);
             scanf("%d",&A[i][j]);
            }

       }

       printf("Element in 2D array : \n");
       for(i=0;i<r;i++)
       {
              for(j=0;j<c;j++)
              {
                     printf("%d ",A[i][j]);
              }
              printf("\n");
       }

       getch();
}

c program to insert element in 2-d array


0 comments:

Post a Comment