C Programming: Find the largest and smallest element values in the 4 & amp; #215; 4 matrix and their row subscript and column subscript, and find the sum of the two main diagonal elements.

Source: Internet
Author: User

C Programming: Find the largest and smallest element values in the 4 & #215; 4 matrix and their row subscript and column subscript, and find the sum of the two main diagonal elements.

// Obtain the largest and least element values in the 4 × 4 matrix and their row subscript and column subscript, and obtain the sum of the two main diagonal elements # include

 
  
Int main () {int sum = 0; int max, min; int max1, max2; // records the coordinates int min1, min2 for the maximum value; // records the coordinates int I for the minimum value, j; int a [4] [4]; // assign an array value for (I = 0; I <4; I ++) {for (j = 0; j <4; j ++) {scanf ("% d", & a [I] [j]) ;}max = min = a [0] [0]; // The minimum initial maximum value is the first element value of the array. a [0] [0] for (I = 0; I <4; I ++) {for (j = 0; j <4; j ++) {if (max <= a [I] [j]) // you need to write =. Otherwise, if the array is all the same number, coordinate uncertainty (you can also initialize the coordinate to (0, 0) and do not need to =) {max = a [I] [j]; max1 = I, max2 = j ;} if (min> = a [I] [j]) {min = a [I] [j]; min1 = I, min2 = j ;}}} printf ("% d \ n", max, min); printf ("max (% d, % d) min (% d) \ n", max1, max2, min1, min2); // calculate the sum of the two main diagonal elements for (I = 0; I <4; I ++) {for (j = 0; j <4; j ++) {if (I = j | (I + j = 3) // key (j = 3-i) sum = sum + a [I] [j] ;}} printf ("sum = % d \ n", sum); 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.