#include <stdio.h>
float average(int [][5],int,int); void search_fail2(int [][5],int); void search_good(int [][5],int); 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; /* printf("please input 5 number(4 line):\n"); for (i = 0; i < 4;i++) { scanf("%d %d %d %d",&arr[i][0],&arr[i][1],&arr[i][2],&arr[i][3],&arr[i][4]); } */ printf("the source data is :\n"); print_source(arr,4); printf("\nthe 1 kemu average is :%.2f\n\n",average(arr,4,0)); search_fail2(arr,4); search_good(arr,4); 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; }
void search_fail2(int arr[][5],int n) { int i,j,(*p)[5],count = 0; float average = 0; p = arr; for (i = 0; i < n;i++) { for (j = 0 ;j < 5; j++) { if (*(*(p+i)+j) < 60) { count++; } } if (count >= 2) { printf("NO.%d is fall,the data is \n",i); for (j = 0; j < 5; j++) { printf("%d ",*(*(p+i)+j)); average += *(*(p+i)+j); } printf("\nthe average is %.2f\n\n",average / 5); } count =0; average = 0; } }
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"); } }
void search_good(int arr[][5],int n) { int i,j,count = 0; int (*p)[5] = arr; float average = 0; for (i = 0; i < n ; i++) { for (j = 0; j < 5; j++) { if (*(*(p + i) + j) >= 85) { count++; } average += *(*(p + i) + j); } if (count == 5 || (average / 5 > 90) ) { printf("the good student is NO.%d\n",i); } count = 0; average = 0; } }
|