How to get smallest number in columns using 2d array.
And my task is to get smallest number in first column only.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
// Two-Dimensional Array
int size = 7;
int i, j, min;
int array[7][7];
// Initializing an array with random numbers
srand(time(NULL));
for (i = 0; i < size; i++)
for ( j = 0; j < size; j++)
array[i][j] = rand()%10;
// Print array
for (i = 0; i < size; i++)
{
for (j = 0; j < size; j++)
printf("%d ", array[i][j]);
printf("\n");
}
// Find min number in column 1
for (j = 0; j < 1; j++) // one column
{
min = array[0][j];
for (i = 0; i < size; i++) // all row
{
if (min > array[i][j])
{
min = array[i][j];
}
}
printf("\nColumn %d min: %d\n", j+1, min);
}
}
Comments
Leave a comment