C program to print a 2D Array using for loop taking user input

In this Program , we will show, how to Print a 2D array by initialization, using for loop and taking user input. Finally, we will Print-Multiple 2D Array Using For Loop and Taking User Input. S0, Let’s Start …

C program to print a 2D Array by initialization

//C program to print a 2D Array using for loop from initialization.
#include<stdio.h>
int main()
{
    int i, j;

    int A[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12} };

    for(i=0; i<3; i++)
    {
        for(j=0; j<4 ; j++)
        {
            printf("%d ", A[i][j]);
        }
        printf("\n");
    }
return 0;
}

C program to print a 2D Array using for loop taking user input

//C program to print a 2D Array using for loop taking user input.
#include<stdio.h>
int main()
{
  int A[3][4], i, j;

  for(i=0; i<3; i++)
  {
    for(j=0; j<4; j++)
    {
      printf("Enter The Elements of A[%d][%d] = ", i, j);
      scanf("%d", &A[i][j]);
    }
    printf("\n");
  }


  printf("The 2D Array is: \n");


  for(i=0; i<3; i++)
  {
    for(j=0; j<4; j++)
    {
      printf("%d ", A[i][j]);
    }
    printf("\n");
  }

return 0;
}

C Program to Print-Multiple 2D Array Using For Loop and Taking User Input

//C Program to Print-Multiple 2D Array Using For Loop and Taking User Input.
#include<stdio.h>
int main()
{
  int A[3][4], B[3][4], i, j;


//Scanning the value of A Matrix.
  for(i=0; i<3; i++)
  {
    for(j=0; j<4; j++)
    {
      printf("Enter The Elements of A[%d][%d] = ", i, j);
      scanf("%d", &A[i][j]);
    }
    printf("\n");
  }

//Printing The Value of A Matrix.
  printf("The B Matrix is: ");
  for(i=0; i<3; i++)
  {
    for(j=0; j<4; j++)
    {
      printf("%d ", A[i][j]);
    }
    printf("\n \t \t ");
  }

 printf("\n");


//Scanning the value of B Matrix.
  for(i=0; i<3; i++)
  {
    for(j=0; j<4; j++)
    {
      printf("Enter The Elements of B[%d][%d] = ", i, j);
      scanf("%d", &B[i][j]);
    }
    printf("\n");
  }

//Printing The Value of B Matrix.
  printf("The B Matrix is: ");
  for(i=0; i<3; i++)
  {
    for(j=0; j<4; j++)
    {
      printf("%d ", B[i][j]);
    }
    printf("\n \t \t ");
  }

return 0;
}

Keep Learning with Prologicode.

Leave a Comment