| 
 
TA的每日心情|  | 开心 2014-6-18 08:29
 | 
|---|
 签到天数: 14 天 [LV.3]偶尔看看II 滴水大师  
 
 
	积分2345 
 | 
 
| 题目 
  
 解决代码及点评
 
 
 
 
 <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/************************************************************************/  /*  50. 求N阶方阵(即N×N数组)中各条反斜线上的元素之和。如4×4数组共有7条反斜线: 25     1       8      12 7     100      3      15 2      5       7       9 8     11      22       6       注:求和时,请按斜线编号顺序显示求出的和。   */  /************************************************************************/  #include <stdio.h>  #include <stdlib.h>  #include <math.h>  #include <string.h>        void main()  {      const int N=5;      int arr[N][N]={0};      int arrnum[N*2-1]={0};      for (int i=0;i<N;i++)      {          for(int j=0;j<N;j++)          {              arr[j]=rand()%10;              printf("%5d",arr[j]);                        }          printf("\n");      }      int m=N-1;int n=0;int cen=1;      int sum=0; int temp=1;      for (int i=0;i<N*N;i++)      {          sum+=arr[m][n];                if (n+1>N-1)          {              m=0;              n=cen-N+1;              cen++;              printf("和为:%d\n",sum);              sum=0;          }          else if (m+1>N-1)           {               m=N-cen-1;               n=0;               cen++;               printf("和为:%d\n",sum);               sum=0;           }          else          {              m++;              n++;          }                 }      system("pause");  }</pre><br><br></pre></pre></pre>  
 
 
 | 
 |