2d array
int a[2][3]= {
{1, 2, 3},
{4, 5, 6}
};
cout << a[1][1]; // Output is 5
2d array
int a[2][3]= {
{1, 2, 3},
{4, 5, 6}
};
cout << a[1][1]; // Output is 5
c program to represent 2d matrix in 1d matrix
#include<stdio.h>
#define n 3
int main()
{
int a[n][n],b[n*n],c[n*n],i,j,k=0,l=0;
printf(“\n Enter elements of 2D array : “);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\n Given 2D array : \n“);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(“%d ”,a[i][j]);
}
printf(“\n”);
}
printf(“\n Row wise \n”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[k]=a[i][j];
k++;
}
}
printf(“\n Column wise \n”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[l]=a[j][i];
l++;
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us