C语言学习笔记 (006) - 二维数组传参的三种表现形式

 1 # include <stdio.h>
 2 # include <stdlib.h>
 3 # define M 6
 4 # define N 5
 5 
 6 int getdate(int (*sp)[M]){
 7     int i,j,x;
 8     for(i=0;i<N;i++,j=0){
 9         while(j<M){
10             x=rand()%41;
11             if(x>=10){
12             sp[i][j]=x;j++;
13             }
14         }
15     }
16     return 0;
17 }
18 
19 int lineave(int s[][M],float a[]){
20     int i,j;
21     float ave = 0.0;
22     for(i=0;i<N;i++,ave = 0.0){
23         for(j=0;j<M;j++){
24             ave = ave +s[i][j];
25         }
26         a[i] = ave/M;
27     }
28     return 0;
29 }
30 
31 int outdate(int sp[N][M],float a[]){
32     int i,j;
33     printf("Output the result :\n");
34     for(i=0;i<N;i++){
35         for(j=0;j<M;j++)
36             printf("%4d\t",sp[i][j]);
37             printf(" :%6.2f\n",a[i]);
38         }
39     printf("\n");
40     return 0;
41 }
42 
43 int main(void){
44     int r[N][M] = {0};
45     float ave[N];
46     getdate(r);
47     lineave(r,ave);
48     outdate(r,ave);
49 }

 

posted @ 2017-08-10 02:52  极客先锋  阅读(502)  评论(0编辑  收藏  举报