#include <stdio.h>
float average(int [][5],int,int); int *search_fail2(int (*)[5]); int *search_good(int (*)[5]); void print_source(int [][5],int); int main(int argc, char *argv[]) { int arr[4][5] ={{80,50,70,65,30},{77,88,99,66,88},{98,95,96,96,92},{66,68,80,30,40}}; //test
int i,j,*p,*p_good; float f_average = 0; printf("the source data is :\n"); print_source(arr,4); printf("\nthe 1 kemu average is :%.2f\n\n",average(arr,4,0)); for (i = 0; i < 4;i++) { p = search_fail2(arr + i); p_good = search_good(arr + i); if (p == *(arr + i)) { printf("No.%d fall score: ",i); for(j = 0; j < 5; j++) { printf("%d ",*(p + j)); f_average += *(p + j); } printf("\nthe average is %.2f\n",f_average / 5); } f_average = 0; if (p_good == *(arr + i)) { printf("No.%d is good student\n",i); } } system("pause"); return 0; }
float average(int arr[][5],int n,int k) { int i,j,(*p)[5]; p = arr; float result = 0; for (i = 0; i < n; i++) { result += *(*(p+i)+k); } return result / n; }
int *search_fail2(int (*point)[5]) { int i,count = 0; int *p = *(point + 1); for (i = 0; i < 5;i++) { if (*(*point + i) < 60) { count ++; } if (count >= 2) { p = point; break; } } return p; }
void print_source(int arr[][5],int n) { int i,j; int (*p)[5] = arr; for (i = 0; i < n; i++) { printf("NO.%d: ",i); for (j = 0; j < 5;j++) { printf("%d ",*(*(p+i)+j)); } printf("\n"); } }
int *search_good(int (*point)[5]) {
int i,count = 0; int *p = *(point + 1); float average = 0; for (i = 0; i < 5;i++) { average += *(*point + i); if (*(*point + i) >= 85) { count ++; } } if (count == 5 || average / 5 > 90) { p = point; } return p; }
|