1 #include<stdio.h> 2 int input_data(int *p,int len)//从键盘输入10个数据 3 { 4 int i = 0; 5 for(i = 0; i < len; i++) 6 { 7 scanf("%d", &p[i]); 8 } 9 return 0; 10 } 11 12 int count_data(int *p, int len ,int *count, int *sum) 13 { 14 int count_data = 0; 15 int sum_data = 0; 16 int i = 0; 17 for(i = 0; i< len; i++){ 18 if(p[i] > 0){ 19 sum_data += p[i]; 20 count_data++; 21 } 22 } 23 *count = count_data; 24 *sum = sum_data; 25 return 0 ; 26 } 27 28 int main(int argc, const char *argv[]) 29 { 30 int count = 0,sum = 0;//定义需要传给形参,给形参赋值的变量 31 int buf[10] = {0}; 32 int len = sizeof(buf)/sizeof(int); 33 int i = 0 ; 34 35 input_data(buf, len); 36 for(i = 0; i < len; i++) 37 { 38 printf("%d ", buf[i]); 39 } 40 41 putchar('\n'); 42 count_data(buf, len, &count, &sum); 43 44 printf("count : %d sum : %d\n", count, sum); 45 return 0; 46 47 }