C and pointer (pointers on C) -- Chapter 8: array (ii) exercises

Source: Internet
Author: User

The exercises in this chapter are classic:

3-4 Unit Matrix

5. Matrix Multiplication

8. Eight queens


Among them, I feel that there is a problem with the eight queens problem. If I do not use the Backtracking Method well, I will not go down first.

Please see http://download.csdn.net/download/wangpegasus/5701765

3,

bool identity_matrix(int matrix[10][10]){int length = 10;for (int i = 0; i < length; i++){for (int j = 0; j < length; j++){if (i==j){if (matrix[i][j] != 1){return false;}else{continue;}}else{if(matrix[i][j] != 0){return false;}else{continue;}}}}}

4,

bool identity_matrix(int *matrix, int n){int length = n;for (int i = 0; i < length; i++){for (int j = 0; j < length; j++){if (i==j){if (*matrix++ != 1){return false;}else{continue;}}else{if(*matrix++ != 0){return false;}else{continue;}}}}}

5,

void matrix_multiply(int *m1, int *m2, int *r, int x, int y, int z){for(int i = 0; i < x; i++){for (int j = 0; j < y; j++){for (int k = 0; k < z; k++){*(r + i + i*k) += *(m1 + i + i*j) * (*(m2 + j + j*k)); }}}}


C and pointer (pointers on C) -- Chapter 8: array (ii) exercises

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.