0% found this document useful (0 votes)
7 views5 pages

Two Dimensional Array Programs

The document provides multiple C programming examples demonstrating the use of two-dimensional arrays. It includes programs for storing and printing a matrix, inputting and outputting a matrix, calculating the sum of elements, adding two matrices, and finding the largest element in a matrix. Each program is accompanied by code snippets and explanations of their functionality.

Uploaded by

tanmaybansal4206
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Two Dimensional Array Programs

The document provides multiple C programming examples demonstrating the use of two-dimensional arrays. It includes programs for storing and printing a matrix, inputting and outputting a matrix, calculating the sum of elements, adding two matrices, and finding the largest element in a matrix. Each program is accompanied by code snippets and explanations of their functionality.

Uploaded by

tanmaybansal4206
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Two Dimensional Array Examples in C

## Program 1: Storing and Printing a 2×3 Matrix

```

#include

int main() {

int arr[2][3] = { {10, 20, 30}, {40, 50, 60} };

printf("Two Dimensional Array Elements:\n");

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

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

printf("%d ", arr[i][j]);

printf("\n");

return 0;

```

## Program 2: Input and Output of 2D Array (Matrix)

```

#include

int main() {

int arr[3][3];

int i, j;
printf("Enter 9 elements for 3x3 matrix:\n");

for (i = 0; i < 3; i++) {

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

scanf("%d", &arr;[i][j]);

printf("\nMatrix is:\n");

for (i = 0; i < 3; i++) {

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

printf("%d ", arr[i][j]);

printf("\n");

return 0;

```

## Program 3: Sum of All Elements in 2D Array

```

#include

int main() {

int arr[2][2] = { {1, 2}, {3, 4} };

int sum = 0;

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

for (int j = 0; j < 2; j++) {


sum += arr[i][j];

printf("Sum of elements = %d\n", sum);

return 0;

```

## Program 4: Addition of Two 2D Arrays

```

#include

int main() {

int a[2][2] = { {1, 2}, {3, 4} };

int b[2][2] = { {5, 6}, {7, 8} };

int c[2][2];

printf("Resultant Matrix:\n");

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

for (int j = 0; j < 2; j++) {

c[i][j] = a[i][j] + b[i][j];

printf("%d ", c[i][j]);

printf("\n");

return 0;
}

```

## Program 5: Find Largest Element in 2D Array

```

#include

int main() {

int arr[3][3] = {

{11, 55, 22},

{9, 88, 66},

{44, 33, 77}

};

int max = arr[0][0];

for (int i = 0; i < 3; i++) {

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

if (arr[i][j] > max) {

max = arr[i][j];

printf("Largest element = %d\n", max);

return 0;

```

You might also like