4.12 使用不同掃描順序來掃描數組同一面的資料。

來源:互聯網
上載者:User

標籤:std   style   oid   void   不同   數組   掃描   for   nbsp   

多種掃描方式訪問這面資料
2, 3, 4,  5,  
8, 9, 10,  
14, 15,  
20


#include <stdio.h>int main(void){ int arr[5][5] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,15, 16,17,18,19,20, 21,22,23,24,25 }; int i,j;#if 1 for(i=0;i<5;i++) { for(j=0;j<5;j++) { printf("%d%d ",i,j); // printf("%3d",arr[i][j]); } putchar(10); } putchar(10);#endif#if 0//掃描方式橫著掃1.1: 2,3,4,5,8,9,10,14,15,20#endif#if 0//掃描方式橫著掃1.2: 5,4,3,2,10,9,8,15,14,20#endif#if 0//掃描方式橫著掃1.3: 20,14,15,8,9,10,2,3,4,5#endif#if 0//掃描方式橫著掃1.4: 20,15,14,10,9,8,5,4,3,2#endif#if 0//掃描方式豎著掃2.1: 2,3,8,4,9,14,5,10,15,20#endif#if 0//掃描方式豎著掃2.2: 5,10,15,20,4.9,14,3,8,2#endif#if 0//掃描方式豎著掃2.3: 2,8,3,14,9,4,20,15,10,5#endif#if 0//掃描方式豎著掃2.4: 20,15,10,5,14,9,4,8,3,2#endif#if 1//掃描方式斜著掃3.1: 2,8,14,20,3,9,15,4,10,5 //方法1 推薦 int z; for(i=0,j=1;j<5;j++) { for(z = 0;z+i<5&&z+j<5;z++) { printf("%3d",arr[z+i][z+j]); } } putchar(10); //方法2 美名找規律,其實有湊數之嫌 for(j=1;j<5;j++) { for(i=0;i<5-j;i++) { printf("%3d",arr[i][j+i]); } } putchar(10);#endif#if 0//掃描方式斜著掃3.2: 5,4,10,3,9,15,2,8,14,20#endif#if 0//掃描方式斜著掃3.3: 2,3,4,8,5,9,10,14,15,20 太難不會。#endif}

 

 

 

4.12 使用不同掃描順序來掃描數組同一面的資料。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.