-->
Showing posts with label 2D Array in C. Show all posts
Showing posts with label 2D Array in C. Show all posts

Wednesday, May 28, 2025

c program to input 2D array element | 2D Array(matrix) examples

 

Matrix program in C[2D examples]




/* 2D array input an output */

#include<stdio.h>
#define row 200
#define column 200
int main()
{
int a[row][column];
int r,c;
int i,j;
printf("enter row and column[0-199] to be used for matrix\n");
scanf("%d%d",&r,&c);//rows and column input
for(i=0;i<=r-1;i++)//for row
{
for(j=0;j<=c-1;j++)//for columns
{
printf("enter element for location %d %d\n",i,j);
scanf("%d",&a[i][j]);
}
}
printf("the matrix is:\n");
for(i=0;i<=r-1;i++)//for row
{
for(j=0;j<=c-1;j++)//for columns
{
printf("%5d",a[i][j]);//printing input with max. width of 5 characters.
}
printf("\n");
}
return 0;
}

Output:-

C program to input elements of mxn matrix