上代码:
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 int main() 5 { 6 int i,j; 7 int a[5][5]; 8 int m = 1,k; 9 for(i = 0; i <5; ++i) 10 { 11 for(j = 0; j < 5; ++j) 12 { 13 a[i][j] = m++; 14 } 15 } 16 17 18 for(i = 0; i <5; ++i) 19 { 20 for(j = 0; j < 5; ++j) 21 { 22 cout<<a[i][j]<<" "; 23 } 24 cout<<endl; 25 } 26 27 i=0; 28 j=4; 29 while(i<5) 30 { 31 for(k=0; k<=i; k++) 32 { 33 cout<<a[k][j-i+k]<<" "; 34 } 35 i++; 36 cout<<endl; 37 } 38 i=1; 39 j=0; 40 while(i<5) 41 { 42 for(int k=i; k<5; k++) 43 { 44 45 cout<<a[k][j+k-i]<<" "; 46 } 47 i++; 48 cout<<endl; 49 } 50 }
时间: 2024-10-04 23:32:55