Multidimensional arrays float studentgradesNUMSTUDENTSNUMCOURSES 0 student 0 1
![Πολυδιάστατοι Πίνακες – Multidimensional arrays • πίνακας με δύο ή περισσότερες διαστάσεις float student_grades[NUM_STUDENTS][NUM_COURSES]; Πολυδιάστατοι Πίνακες – Multidimensional arrays • πίνακας με δύο ή περισσότερες διαστάσεις float student_grades[NUM_STUDENTS][NUM_COURSES];](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-1.jpg)






![Τι πρεπει να γινει; • διαβαστουν δεδομενα (αποθηκευτουν) void read_data(float grades_table[80][5]); • υπολογισμος μεσων Τι πρεπει να γινει; • διαβαστουν δεδομενα (αποθηκευτουν) void read_data(float grades_table[80][5]); • υπολογισμος μεσων](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-8.jpg)
![σταθερες #define NUM_STUDENTS 80 #define NUM_COURSES 5 πινακες float grade_table[NUM_STUDENTS][NUM_COURSES]; float average_per_student[NUM_STUDENTS]; float average_per_course[NUM_COURSES]; σταθερες #define NUM_STUDENTS 80 #define NUM_COURSES 5 πινακες float grade_table[NUM_STUDENTS][NUM_COURSES]; float average_per_student[NUM_STUDENTS]; float average_per_course[NUM_COURSES];](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-9.jpg)
![void read_data(float grade_table[][NUM_COURSES]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i) for(j=0; j<NUM_COURSES; ++j) scanf(“%f”, void read_data(float grade_table[][NUM_COURSES]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i) for(j=0; j<NUM_COURSES; ++j) scanf(“%f”,](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-10.jpg)
![void compute_averages(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i) void compute_averages(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i)](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-11.jpg)
![void display_results(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i){ void display_results(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i){](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-12.jpg)


![void read_data(float grade_table[][NUM_COURSES], int *students, int *courses) { int i, j; scanf(“%d %d”, students, void read_data(float grade_table[][NUM_COURSES], int *students, int *courses) { int i, j; scanf(“%d %d”, students,](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-15.jpg)
![void compute_averages(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[], int students, int courses) { int i, void compute_averages(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[], int students, int courses) { int i,](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-16.jpg)
![void display_results(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[], int students, int courses) { int i, void display_results(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[], int students, int courses) { int i,](https://slidetodoc.com/presentation_image_h2/5f46b26c82d899fc65217765fe47c402/image-17.jpg)

- Slides: 18
Πολυδιάστατοι Πίνακες – Multidimensional arrays • πίνακας με δύο ή περισσότερες διαστάσεις float student_grades[NUM_STUDENTS][NUM_COURSES]; 0 student 0 1 2 3 4 5 course 1 2 3 Δυσδιαστατοι πινακες ΝUM_STUDENTS rows NUM_COURSES columns
Τι πρεπει να γινει; • διαβαστουν δεδομενα (αποθηκευτουν) void read_data(float grades_table[80][5]); • υπολογισμος μεσων ορων void compute_averages(float grades_table[80][5], float average_per_student[80], float average_per_course[5]); • τυπωση αποτελεσματων void display_results(float grades_table[80][5], float average_per_student[80], float average_per_course[5]);
σταθερες #define NUM_STUDENTS 80 #define NUM_COURSES 5 πινακες float grade_table[NUM_STUDENTS][NUM_COURSES]; float average_per_student[NUM_STUDENTS]; float average_per_course[NUM_COURSES];
void read_data(float grade_table[][NUM_COURSES]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i) for(j=0; j<NUM_COURSES; ++j) scanf(“%f”, &grade_table[i][j]); }
void compute_averages(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i) average_per_student[i]=0; for(i=0; i<NUM_COURSES; ++i) average_per_course[i]=0; for(i=0; i<NUM_STUDENTS; ++i) for(j=0; j<NUM_COURSES; ++j){ average_per_student[i]+=grade_table[i][j]; average_per_course[j]+= grade_table[i][j]; } for(i=0; i<NUM_STUDENTS; ++i) average_per_student[i]/=NUM_COURSES; for(i=0; i<NUM_COURSES; ++i) average_per_course[i]/=NUM_STUDENTS; }
void display_results(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[]) { int i, j; for(i=0; i<NUM_STUDENTS; ++i){ for(j=0; j<NUM_COURSES; ++j) printf(“%5. 2 f ”, grade_table[i][j]); printf(“%5. 2 fn”, average_per_student[i]; } for(j=0; j<NUM_COURSES; ++j) printf(“%5. 2 f ”, average_per_course[j]); printf(“n”); }
void read_data(float grade_table[][NUM_COURSES], int *students, int *courses) { int i, j; scanf(“%d %d”, students, courses); if (*students>NUM_STUDENTS || *courses>NUM_COURSES){ printf(“error: students or courses > than allowed maximum”); exit(0); } for(i=0; i<*students; ++i) for(j=0; j<*courses; ++j) scanf(“%f”, &grade_table[i][j]); }
void compute_averages(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[], int students, int courses) { int i, j; for(i=0; i<students; ++i) average_per_student[i]=0; for(i=0; i<courses; ++i) average_per_course[i]=0; for(i=0; i<students; ++i) for(j=0; j<courses; ++j){ average_per_student[i]+=grade_table[i][j]; average_per_course[j]+= grade_table[i][j]; } for(i=0; i<students; ++i) average_per_student[i]/=courses; for(i=0; i<courses; ++i) average_per_course[i]/=student; }
void display_results(float grade_table[][NUM_COURSES], float average_per_student[], float average_per_course[], int students, int courses) { int i, j; for(i=0; i<students; ++i){ for(j=0; j<courses; ++j) printf(“%5. 2 f ”, grade_table[i][j]); printf(“%5. 2 fn”, average_per_student[i]; } for(j=0; j<courses; ++j) printf(“%5. 2 f ”, average_per_course[j]); printf(“n”); }