Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

Find Minimum and Maximum in 2D Array - C Program

Find Minimum and Maximum in 2D Array - C Program

✅ Find Minimum and Maximum in 2D Array - C Program

#include <stdio.h>

int main() {
    int row, col;

    // Input number of rows and columns
    printf("Enter number of rows and columns:\n");
    scanf("%d %d", &row, &col);

    int arr[row][col];

    // Input 2D array elements
    printf("Enter %d elements:\n", row * col);
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) {
            scanf("%d", &arr[i][j]);
        }
    }

    // Initialize min and max with the first element
    int min = arr[0][0];
    int max = arr[0][0];

    // Traverse the array to find min and max
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) {
            if(arr[i][j] < min) {
                min = arr[i][j];
            }
            if(arr[i][j] > max) {
                max = arr[i][j];
            }
        }
    }

    // Print results
    printf("Minimum element = %d\n", min);
    printf("Maximum element = %d\n", max);

    return 0;
}
  

πŸ“˜ Explanation:

This C program reads a 2D array (matrix) from the user, then traverses all its elements using nested loops to determine the minimum and maximum values. The min and max variables are initialized with the first element, and the program compares each subsequent value to update these accordingly. This logic is useful for matrix-based problems in C, including search, statistics, and data processing.

🧾 Sample Output:

Enter number of rows and columns:
2 3
Enter 6 elements:
5 7 1 9 4 2
Minimum element = 1
Maximum element = 9
  

πŸ”‘ Keywords:

2D Array in C, Matrix traversal, Find min in matrix, Find max in matrix, C program array problem, Nested loop logic in C

πŸ“Œ Hashtags:

#CProgramming #2DArray #MatrixMinMax #BeginnerC #ArrayTraversal #CodingPractice

Comments

Popular Posts

πŸŒ™