Program (Without Using Function)
#include <stdio.h> int main() { printf("**************************************************************"); printf("\n**************************************************************"); printf("\n** WAP to find minimum element from a 2-D array **"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n**************************************************************"); printf("\n**************************************************************\n"); int r, c, i, j, a[10][10], min; printf("Enter no. of rows and columns in the array\n"); scanf("%d%d", &r, &c); printf("enter array elements"); for (i = 0; i < r; i++) for (j = 0; j < c; j++) scanf("%d", &a[i][j]); min = a[0][0]; for (i = 0; i < r; i++) for (j = 0; j < c; j++) if (a[i][j] < min) min = a[i][j]; printf("Minimum of elements of array is %d", min); return 0; }
Output
************************************************************** ************************************************************** ** WAP to find minimum element from a 2-D array ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ************************************************************** ************************************************************** Enter no. of rows and columns in the array 3 3 enter array elements 23 45 65 12 23 43 9 45 56 Minimum of elements of array is 9
Program (Using Function)
#include <stdio.h> int findmin(int a[][10], int r, int c); int main() { printf("**************************************************************"); printf("\n**************************************************************"); printf("\n** WAP to find minimum element from a 2-D array **"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n**************************************************************"); printf("\n**************************************************************\n"); int r, c, i, j, a[10][10]; printf("Enter no. of rows and columns in the array\n"); scanf("%d%d", &r, &c); printf("enter array elements"); for (i = 0; i < r; i++) for (j = 0; j < c; j++) scanf("%d", &a[i][j]); printf("Minimum of elements of array is %d", findmin(a, r, c)); return 0; } int findmin(int a[][10], int r, int c) { int i, j, min; min = a[0][0]; for (i = 0; i < r; i++) for (j = 0; j < c; j++) if (a[i][j] < min) min = a[i][j]; return min; }
Output
************************************************************** ************************************************************** ** WAP to find minimum element from a 2-D array ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ************************************************************** ************************************************************** Enter no. of rows and columns in the array 3 3 enter array elements 23 34 54 12 32 21 6 57 43 Minimum of elements of array is 6