Answer to Question #302331 in C for Piddy

Question #302331

How to get smallest number in columns using 2d array.

And my task is to get smallest number in first column only.


1
Expert's answer
2022-02-24T12:17:48-0500
#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);        
    }                  
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS