Find in a two-dimensional array of "C", the young matrix in a two-dimensional array, each row is sorted in ascending order from left to right, enter an array and a number, and infer whether the number is included in the array

Source: Internet
Author: User

  finding in a two-dimensional array, the young matrix is in a two-dimensional array. Each row is sorted in ascending order from left to right.

Each column is sorted in ascending order from top to bottom. Please complete a function, enter such an array and a number. Infer if the array contains this number # include <stdio.h> #define COL 4#define rol 4int yang (int (*p) [col], int num) {int i = 0;int J = Col-1;wh Ile (j+1) {int *q = & (P[i][j]), if (*q = = num) return 1;else if (*q < num) {p++;} else if (*q > num) {q--;j--;}} return-1;} int main () {int Arr[rol][col] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, ten, one, and};p rintf ("%d\n", ya Ng (arr, 6));p rintf ("%d\n", Yang (arr.));p rintf ("%d\n", Yang (arr.));p rintf ("%d\n", Yang (arr, 1));p rintf ("%d\n", Yang (arr, +)); return 0;}







Find in a two-dimensional array of "C", the young matrix in a two-dimensional array, each row is sorted in ascending order from left to right, enter an array and a number, and infer whether the number is included in the array

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.