函数参数传递数组

1、示例

#include<stdio.h>
float average(float array[],int n)
{
 
 
     int i;
     float aver, sum = 0;
     for ( i = 0; i < n; i++)
         sum = sum + array[i];
     aver = sum / n;
     return aver;
}
int main( )
 {
 
 
     float score1[5] ;
     float score2[10] ;
     int i;
     for( i = 0 ; i < 5 ; i++)
         scanf("%f",&score1[i]);
     printf("average score1 is: %f\n", average(score1, 5));
     for( i = 0 ; i < 10 ; i++)
         scanf("%f",&score2[i]);
     printf("average score2 is: %f\n", average(score2, 10));
     return 0;
 }

2、其它示例

int array(char buf[60]);
int array(char buf[])
int array(char * buf)
int array2(char array[10][30])
int array(char array[][30])
int array(char (*array)[30])

  

  

posted @ 2021-08-06 19:31  zhaogaojian  阅读(159)  评论(0编辑  收藏  举报