Incorrect number of failed prints

CSDN Q & A 2021-12-30 05:30:16 阅读数:940

incorrect number failed prints
#include <stdio.h>#define N 3int ave(int a);int i, max, max_i;float a, b, c, d, e, f;int score[N];char name[N][10];int number[N];int main () { int counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, counter5 = 0, counter6 = 0; int F[N], AboveAvg[N]; for (i = 0; i < N; i++) { printf (" name :\t"); scanf ("%s", &name[i]); printf(" achievement :\t"); scanf("%d", &score[i]); printf(" Student number :\t"); scanf("%d", &number[i]); if (score[i] < 0) break; else if (score[i] >= 90) counter1++; else if (score[i] >= 80) counter2++; else if (score[i] >= 70) counter3++; else if (score[i] >= 60) counter4++; else { F[counter5] = i; // Record the subscript of the person who failed Convenient for subsequent traversal  counter5++; } } int p, j; f = ave(a); for (p = 0; p < N; p++) { if (score[p] > f) { AboveAvg[counter6] = p; // Empathy  counter6++; } } max = score[0]; max_i = 0; for (j = 0; j < N; j++) { if (max < score[j]) { max = score[j]; max_i = j; } } a = (counter1 * 100.0 / N); b = (counter2 * 100.0 / N); c = (counter3 * 100.0 / N); d = (counter4 * 100.0 / N); e = (counter5 * 100.0 / N); printf(" The highest score is :%d branch , Its student number is :%d\n", max, number[max_i]); printf(" What are the reasons for failing :%d people , The percentage is :%.2f%%\n", counter5, e); printf(" Who failed :"); for ( i = 0; i < counter5; i++) { printf("%s\t", name[i]); } printf("\n fraction >=90 The percentage is :%.2f%%\n", a); printf("90> fraction >=80 The percentage is :%.2f%%\n", b); printf("80> fraction >=70 The percentage is :%.2f%%\n", c); printf("70> fraction >=60 The percentage is :%.2f%%\n", d); printf(" Above the average score are :%d people \n", counter6); printf(" People who are above average have :"); for ( i = 0; i < counter6; i++) { printf("%s\t", name[i]); } printf("\n"); return 0;}int ave(int a) { int total = 0, i, b; for (i = 0; i < N; i++) { total += score[i]; } b = total / N; return b;}



Refer to the answer 1:
#include <stdio.h>#define N 3int ave(int a);int i, max, max_i;float a, b, c, d, e, f;int score[N];char name[N][10];int number[N];int main () { int counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, counter5 = 0, counter6 = 0; int F[N], AboveAvg[N]; for (i = 0; i < N; i++) { printf (" name :\t"); scanf ("%s", &name[i]); printf(" achievement :\t"); scanf("%d", &score[i]); printf(" Student number :\t"); scanf("%d", &number[i]); if (score[i] < 0) break; else if (score[i] >= 90) counter1++; else if (score[i] >= 80) counter2++; else if (score[i] >= 70) counter3++; else if (score[i] >= 60) counter4++; else { F[counter5] = i; // Record the subscript of the person who failed Convenient for subsequent traversal  counter5++; } } int p, j; f = ave(a); for (p = 0; p < N; p++) { if (score[p] > f) { AboveAvg[counter6] = p; // Empathy  counter6++; } } max = score[0]; max_i = 0; for (j = 0; j < N; j++) { if (max < score[j]) { max = score[j]; max_i = j; } } a = (counter1 * 100.0 / N); b = (counter2 * 100.0 / N); c = (counter3 * 100.0 / N); d = (counter4 * 100.0 / N); e = (counter5 * 100.0 / N); printf(" The highest score is :%d branch , Its student number is :%d\n", max, number[max_i]); printf(" What are the reasons for failing :%d people , The percentage is :%.2f%%\n", counter5, e); printf(" Who failed :"); for ( i = 0; i < counter5; i++) { printf("%s\t", name[F[i]]); } printf("\n fraction >=90 The percentage is :%.2f%%\n", a); printf("90> fraction >=80 The percentage is :%.2f%%\n", b); printf("80> fraction >=70 The percentage is :%.2f%%\n", c); printf("70> fraction >=60 The percentage is :%.2f%%\n", d); printf(" Above the average score are :%d people \n", counter6); printf(" People who are above average have :"); for ( i = 0; i < counter6; i++) { printf("%s\t", name[AboveAvg[i]]); } printf("\n"); return 0;}int ave(int a) { int total = 0, i, b; for (i = 0; i < N; i++) { total += score[i]; } b = total / N; return b;}



Refer to the answer 2:
版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2021/12/202112300530150165.html