#include<stdio.h> float aver(float* p) { float sum = 0; int i; for (i = 0; i < 20; i += 4) { //关于第0列求和 sum += *(p + i); } return sum; } int well(float* p) { int i, flag = 0; float sum=0; for (i = 0; i < 4; i++) { sum += *(p + i); if (*(p + i) >= 85 ) flag += 1; if (flag == 4) return 1; //数人头类型,满足条件就返回1;不满足就返回0(没有) } if (sum / 4 >= 90) return 1; return 0; } int fals(float* p) { int count = 0, flag = 0; float* a = p; for (; p < a + 4; p++) { //使用数组地址进行循环 (改变p,进行地址计算) if (*(p) < 60) flag += 1; if (flag == 2) { count += 1; break; } } if (flag == 2) return 1; else return 0; } int main() { float stu[5][4], a; int i, j, exce=0, unpass=0; for (i = 0; i < 5; i++) { for (j = 0; j < 4; j++) { scanf("%f", &stu[i][j]); } } for (i = 0; i < 5; i++) { exce += well(stu[i]); unpass += fals(stu[i]); } a = aver(stu[0]) / 5; printf("%.1f ", a); printf("%d ", unpass); printf("%d", exce); return 0; }
使用数组指针传递进入函数,直接掏数组老窝a[0]数组首地址;a[i]多维数组每一行的首地址
标签:return,int,sum,float,++,flag,数组,多维,指针 From: https://www.cnblogs.com/LXYlxy666/p/17139313.html