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:-
No comments:
Post a Comment