C Two-dimensional array exercises

Source: Internet
Author: User

The requirements for this example are:

* In a two-dimensional integer array of n rows n columns, *
Select two numbers according to the following requirements.
* First select the maximum number from each line, and select the minimum number from the selected n maximum number;
* Second, select the minimum number from each line, and then select the maximum number from the selected n decimal places. *

Here's my Code, and in the comments I can see my idea:

#include <stdio.h>/** * Instance requirements: * In a two-dimensional integer array of n rows n columns, * Two numbers are selected according to the following requirements. * First select the maximum number from each row, select the minimum number from the selected n maximum number, and second, select the minimum number from each row, and then select the maximum number from the selected n decimal places. * */intMainvoid){intOrder printf"%s\n","Please enter the order of the Matrix:"); scanf"%d", &order); printf"Please input the elements of the Matrix,from a[0][0] to a[%d][%d]:\n", order-1, order-1);intMatrix[order][order];/** * Get user input and populate in a two-dimensional array */    intColums,rows; for(rows =0; rows < order;rows++) { for(colums =0; Colums < order;colums++) {scanf ("%d", &matrix[rows][colums]);//This can also be written here            //scanf ("%d", matrix[rows]+colums);}    }/** * Find the smallest element of the largest element * */    //To hold the smallest element in the largest element    intMininmax =0; for(rows =0; rows < order;rows++) {//To save the maximum line element        intMaxinline =0; for(colums =0; colums < order;colums++) {if(Matrix[rows][colums] > Maxinline) maxinline = Matrix[rows][colums]; }if(Rows = =0){//When getting the largest element of the first row, assign the value to the smallest element directlyMininmax = Maxinline; }Else{if(Mininmax > Maxinline) mininmax = Maxinline; }} printf ("The minimum of maximum number is%d.\n", Mininmax);/** * Find the largest element of the smallest element * */    //To hold the largest element in the smallest element    intMaxinmin =0; for(rows =0; rows < order;rows++) {//To save the minimum line element        intMininline = matrix[rows][0]; for(colums =0; colums < order;colums++) {if(Matrix[rows][colums] < mininline) Mininline = Matrix[rows][colums]; }if(Rows = =0){//When obtaining the smallest element of the first row, assign the value directly to the largest elementMaxinmin = Mininline; }Else{if(Maxinmin < Mininline) maxinmin = Mininline; }} printf ("The maximum of minimum number is%d.\n", maxinmin);return 0;}

C Two-dimensional array exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.