1 条题解
-
0
C :
#include<stdio.h> int main(){ int a[10][10]; int i,j,n; scanf("%d",&n); for(i = 0;i < n;i++){ for(j = i;j < n;j++){ a[i][j] = i + 1; a[j][i] = i + 1; } } for(i = 0;i < n;i++){ for(j = 0;j < n;j++){ printf("%3d",a[i][j]); } printf("\n"); } return 0; }
C++ :
#include<iostream> #include<iomanip> using namespace std; int main(){ int n; int a[11][11]; cin>>n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i<=j) { a[i][j] = i+1; } else { a[i][j] =j+1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout<<setw(3)<<a[i][j]; } cout<<endl; } }
Python :
def getList(m,n): ''' m 行数 n 列数 返回的是m行n列的二维数组,默认值为0 ''' ma = [ [0 for i in range(n)] for i in range(m) ] return ma def printList(arr): for i in arr: for j in i: print('%3d' %(j) ,end='') print(); n = int( input() ); a = getList(n,n) for i in range(0,n): for j in range(i,n): a[i][j] = i + 1; a[j][i] = a[i][j] printList(a)
- 1
信息
- ID
- 2116
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者