Write a difference between one dimensional and two dimensional array in c

Write a difference between one dimensional and two dimensional array in c

Difference between one dimensional and two-dimensional array in c

One dimensional array

Two dimension array

It consists of only one subscript

It consists of two subscript

The maximum size will be sized of an array which we define in the program.

Maximum size will be the product of row and the column size of the array, which we define in the program.

It stores either data row-wise or column-wise.

It stores either data in matrix form that is row and column-wise.

Syntax

data_type array_name[size];

Syntax

data_type array_name[row size][column size];

Example

Int a[15];

Example

Int a[3][2];

Program

#include<stdio.h>

#include<conio.h>

void main()

{

int i num[5];

printf(“\n Enter elements:”);

for(i=0;i<5;i++)

{

scanf(“%d”,&num[i]);

}

printf(“\n Array element are:”);

for(i=0;i<5;i++)

{

printf(“%d\t”, num[i]);

}

getch();

}

Program

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j;

int matrix[2][2]={100,200,300,400};

printf(“\n The 2X3 matrix is:”);

for(i=0;i<2;i++)

{

for(j=0;j<3;j++)

{

printf(“%d\t”, matrix[i][j]);

}

printf(“\n”);

}

getch();

}

 

Post a Comment

0 Comments