On the problem of matrices

Source: Internet
Author: User

Title : Clockwise print matrix

Void printnumber (int x) {                 cout << x <<  " " &NBSP;;} Void printmatrixincircle (int  (*num) [4], int cols , int rows, int  Start) {                  int endx = cols - 1 - start;                  int endy = rows - 1  - start;                  //print a line from left to right                   for  (int i = start; i <= endx; ++i)                  {                                   int number = num [start][i];                                  printnumber (number);                 }                  //print a column from top to bottom                   if  (Start < endy)                  {                                   for  (Int i = start + 1; i <= endy; ++i)                                  {                                                    int number = num [i][endx];                                            &nBsp;      printnumber (number);                                  }                 }                  //print a line from right to left                   if  (Start < endx&&start < endy)                  {                                   for  (int i = endx -  1; i >=&Nbsp;start; --i)                                  {                                                    int number = num  [endy][i];                                                  printnumber (number);                                  }                 }                  //print a line from bottom to top                   if  (start < endx&&start<endy-1)                  {                                   for  (Int i = endy  - 1; i >= start + 1; --i)                                   {                                                   int  number = num [i][start];                                                   printnumber (number);                                  }                }}void  printmatrixclockwisely (INT&NBSP; (*num) [4], int cols , int rows] {                  if  (num == null | |  cols <= 0 | |  rows <= 0)                                    return;                  int start = 0;                  while  (cols > start * 2 &&  ROWS&NBSP;&GT;&NBSP;START&NBSP;*&NBSP;2)                  {                                  Printmatrixincircle ( num, cols , rows, start);                                  ++start;                 }}


This article is from the "incomparable Warm yang" blog, please be sure to keep this source http://10797127.blog.51cto.com/10787127/1775973

On the problem of matrices

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.