C Two-dimensional array exercises

Source: Internet
Author: User

C Two-dimensional array exercises

The requirements for this instance are:

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

The following is my code. I can see my thoughts in the comments:

# Include
  
   
/*** Instance requirement: * in the two-dimensional integer array of n rows and n columns, * two numbers are selected according to the following requirements. * First, select the maximum number from each row, and then select the minimum number from the n largest numbers. * Second, select the minimum number from each row, then, select the maximum number from the n decimal places. **/Int main (void) {int order; 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); int matrix [order] [order];/*** get user input and fill it in a two-dimensional array */int colums, rows; for (rows = 0; rows <order; rows ++) {for (colums = 0; colums <order; colums ++) {scanf ("% d ", & matrix [rows] [colums]); // You can also write it here // scanf ("% d", matrix [rows] + colums );}} /*** find the minimum element of the maximum element ** // It is used to save the minimum element int minInMax = 0; for (rows = 0; rows <order; rows ++) {// used to save the maximum Row Element int maxInLine = 0; for (colums = 0; colums <order; colums ++) {if (matrix [rows] [colums]> maxInLine) maxInLine = matrix [rows] [colums];} if (rows = 0) {// when the maximum element of the first line is obtained, the minimum element minInMax = maxInLine is assigned directly;} else {if (minInMax> maxInLine) minInMax = maxInLine ;}} printf ("The minimum of maximum number is % d. \ n ", minInMax);/*** find the maximum element of the smallest element ** // It is used to save the maximum element int maxInMin = 0; for (rows = 0; rows <order; rows ++) {// used to save the minimum element int minInLine = matrix [rows] [0]; for (colums = 0; colums <order; colums ++) {if (matrix [rows] [colums] <minInLine) minInLine = matrix [rows] [colums];} if (rows = 0) {// when the minimum element of the first line is obtained, the maximum element maxInMin = minInLine is assigned directly;} else {if (maxInMin <minInLine) maxInMin = minInLine ;}} printf ("The maximum of minimum number is % d. \ n ", maxInMin); return 0 ;}
  

Related Article

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.