Solved programming problem

How to find the minimum value from a 2D array.

Source code

#include<stdio.h>

int main()

{

    int array[100][100];/// declare a 2D Array.

    int i,j,r,c;

    printf("Please Enter The Row Number:");

    scanf("%d",&r);

    printf("Please Enter The Column Number:");

    scanf("%d",&c);

    printf("Please Enter %d X %d Element Of the array: ",r,c);

    for(i=0; i<r; i++) ///scan array element

    {

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

        {

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

        }

    }

    int min=array[0][0];///set index 0 0 as minimum.

    printf("The Minimum Element of the array:");

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

    {

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

        {

            if(array[i][j]<min)///Checking the number is smaller then min or not.

            {

                min=array[i][j];

            }

        }

    }

     printf("%d",min);

    return 0;

}

Output

Please Enter The Row Number: 3

Please Enter The Column Number: 3

Please Enter 3 x 3 Element Of the array:

1 2 3

4 5 6

7 8 9

The Minimum Element of the array: 1

 

Join the discussion

Add your comment