Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define STUDENTS 20
- #define ASSIGNMENTS 5
- void fillArrayRand(int grades[STUDENTS][ASSIGNMENTS])
- {
- for(int i=0;i<STUDENTS;i++){
- for(int j=0;j<ASSIGNMENTS;j++){
- grades[i][j]=rand()%10-1;
- }
- }
- }
- void fillArray(int grades[STUDENTS][ASSIGNMENTS])
- {
- int grade = 0;
- int j;
- for(int i=0;i<STUDENTS;i++){
- j = 0;
- printf("\nStudent %d: Please fill the grades. (type number and press Enter.)\n", i+1);
- while(j != ASSIGNMENTS){
- printf("Please, type:\t");
- scanf("%d", &grade);
- if (grade >= -1 && grade <= 10){
- grades[i][j] = grade;
- printf("\tSuccess! Go on.\n");
- j++;
- }
- else {
- printf("\tGrade not valid! Repeat.\n");
- }
- }
- }
- }
- void printArray(int grades[STUDENTS][ASSIGNMENTS])
- {
- printf("Printing the formatted array ->\n");
- printf("Students\t"); for(int i = 0;i<ASSIGNMENTS;i++) printf("Assignment #%d\t", i+1);
- printf("\n");
- for(int i=0;i<STUDENTS;i++){
- printf("\t%d\t\t", i+1);
- for(int j=0;j<ASSIGNMENTS;j++){
- printf("%d\t\t", grades[i][j]);
- }
- printf("\n");
- }
- printf("===============================\n");
- }
- void findMax(int grades[STUDENTS][ASSIGNMENTS])
- {
- printf("Best grade of each student ->\n");
- int max, pos;
- printf("Students\tBest Grade\tAssignment (*)\n");
- for(int i=0;i<STUDENTS;i++){
- pos = 0;
- printf("\t%d\t", i+1);
- max = -2;
- for(int j=0;j<ASSIGNMENTS;j++){
- if (grades[i][j] > max)
- {
- max = grades[i][j];
- pos = j + 1;
- }
- }
- printf("\t%d\t\t%d\n", max, pos);
- }
- printf("(*The best grade was achieved at this assignment.)\n");
- printf("===============================\n");
- }
- void findMin(int grades[STUDENTS][ASSIGNMENTS])
- {
- printf("Worst grade per assignment ->\n");
- int min, pos;
- printf("Assignments\tWorst Grade\tStudent (*)\n");
- for(int j=0;j<ASSIGNMENTS;j++){
- min = 10;
- pos = 0;
- printf("\t%d\t", j+1);
- for(int i=0;i<STUDENTS;i++){
- if (grades[i][j] <= min && grades[i][j] != -1)
- {
- min = grades[i][j];
- pos = i + 1;
- }
- }
- printf("\t%d\t\t%d\n", min, pos);
- }
- printf("(*The student whose grade was the worst at the specific assignment.)\n");
- printf("===============================\n");
- }
- void findMean(int grades[STUDENTS][ASSIGNMENTS])
- {
- printf("Mean grade of each student ->\n");
- double sum = 0, counter = 0;
- double mean;
- printf("Students\tMean Grade\n");
- for(int i=0;i<STUDENTS;i++){
- printf("\t%d\t", i+1);
- for(int j=0;j<ASSIGNMENTS;j++){
- if (grades[i][j] != -1)
- {
- sum += grades[i][j];
- counter++;
- }
- }
- mean = sum/counter;
- printf("\t%f\n", mean);
- }
- printf("===============================\n");
- }
- void checkIfEligible(int grades[STUDENTS][ASSIGNMENTS])
- {
- int sum, counter;
- printf("Eligibility for the exam ->\n");
- printf("Students\tEligible\tNotes\n");
- for(int i=0;i<STUDENTS;i++){
- sum = 0;
- counter = 0;
- printf("\t%d\t", i+1);
- for(int j=0;j<ASSIGNMENTS;j++){
- if (grades[i][j] != -1)
- {
- sum += grades[i][j];
- counter++;
- }
- }
- (sum >= 25 && counter >=3) ? printf("Yes") : printf("No");
- printf("\t\t(sum of grades = %d, submitted assignments = %d)\n", sum, counter);
- /*if (sum >= 25 && counter >= 3)
- {
- printf("Yes")
- }
- else
- {
- printf("\n");
- }*/
- }
- printf("===============================\n");
- }
- int main()
- {
- int grades[STUDENTS][ASSIGNMENTS];
- fillArrayRand(grades); // γεμίζει τον 2Δ πίνακα με τυχαίους βαθμούς (-1 έως 10)
- printArray(grades); // τυπώνει όμορφα τον πίνακα των βαθμών
- findMax(grades);
- findMin(grades);
- findMean(grades);
- checkIfEligible(grades);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement