Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

2 D Array Question

2 d array notes

Uploaded by

ayush singh
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)
22 views

2 D Array Question

2 d array notes

Uploaded by

ayush singh
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
You are on page 1/ 3

Take input of the 2d array from user

int a[3][3], b[3][3], sum[3][3];


printf("Enter elements of first matrix (3x3):\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
scanf("%d", &a[i][j]);
}}

Sum of matrix
#include <stdio.h>
int main() {
int a[3][3], b[3][3], sum[3][3];
printf("Enter elements of first matrix (3x3):\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
scanf("%d", &a[i][j]);
}
}

printf("Enter elements of second matrix (3x3):\n");


for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
scanf("%d", &b[i][j]);
}
}

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


for(int j = 0; j < 3; j++) {
sum[i][j] = a[i][j] + b[i][j];
}
}

printf("Sum of matrices:\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
return 0;
}
Find biggest element In array matrix
#include <stdio.h>
int main() {
int mat[5][5], max;
printf("Enter elements of the matrix (5x5):\n");
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 5; j++) {
scanf("%d", &mat[i][j]);
}
}

max = mat[0][0];
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 5; j++) {
if(mat[i][j] > max) {
max = mat[i][j];
}
}
}

printf("Maximum element in the matrix = %d\n", max);


return 0;
}

Find the number in matrix


#include <stdio.h>
int main() {
int n, m, mat[10][10], x, found = 0;
printf("Enter size of matrix (NxM): ");
scanf("%d%d", &n, &m);
printf("Enter elements of the matrix:\n");
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
scanf("%d", &mat[i][j]);
}
}

printf("Enter element to search: ");


scanf("%d", &x);

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


for(int j = 0; j < m; j++) {
if(mat[i][j] == x) {
printf("Element %d found at position (%d, %d)\n", x, i + 1, j + 1);
found = 1;
break;
}
}

}
if(!found) {
printf("Element not found\n");
}
return 0;
}

You might also like