1155: 零起点学算法62——输出矩阵
Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 997 Accepted: 557
[ Submit ][ Status ][ Web Board ]
Description
输出n*m的矩阵
Input
多组测试数据
每组输入2个整数 n和m(不大于20)
Output
输出n*m的矩阵,要求左上角元素是1,然后从左到右 从上到下依次增大
Sample Input
3 4
Sample Output
1 2 3 4 5 6 7 8 9 10 11 12
Source
零起点学算法
1 #include<stdio.h>
2 int main(){
3 int n,m,a[ 20 ][ 20 ];
4 while (scanf( " %d%d " ,&n,&m)!= EOF){
5 int t= 1 ;
6 for ( int i= 0 ;i<n;i++ ){
7 for ( int j= 0 ;j<m;j++ ){
8 a[i][j]= t;
9 t++ ;
10 }
11 }
12
13 for ( int i= 0 ;i<n;i++ ){
14 for ( int j= 0 ;j<m- 1 ;j++ ){
15 printf( " %d " ,a[i][j]);
16 }
17 printf( " %d\n " ,a[i][m- 1 ]);
18 }
19 }
20 return 0 ;
21 }
查看更多关于1155: 零起点学算法62——输出矩阵的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did238296