Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 128
- struct student
- {
- char surname[MAX];
- int exams[3];
- double av;
- } st[MAX];
- typedef struct student struct_t[MAX];
- int struct_input(struct_t st, int n)
- {
- for (int i = 0; i < n; i++)
- {
- printf("Input Surname: ");
- if (scanf("%s", st[i].surname) != 1)
- return EXIT_FAILURE;
- printf("Input marks: ");
- if (scanf("%d %d %d", &st[i].exams[0], &st[i].exams[1], &st[i].exams[2]) != 3)
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- int struct_output(struct_t st, int n)
- {
- for (int i = 0; i < n - 2; i++)
- {
- printf("\nSurname is %s", st[i].surname);
- printf("\nMarks are: %d %d %d", st[i].exams[0], st[i].exams[1], st[i].exams[2]);
- st[i].av = (st[i].exams[0] + st[i].exams[1] + st[i].exams[2]) / 3.0;
- printf("\nAverage score is: %lf", st[i].av);
- }
- return EXIT_SUCCESS;
- }
- int del_student(struct_t st, int n)
- {
- double sum = 0.0;
- double av_sum;
- for (int i = 0; i < n; i++)
- sum += st[i].av;
- av_sum = sum / n;
- float max_1 = fabs(av_sum - st[0].av);
- int max_1i = 0;
- float max_2 = fabs(av_sum - st[1].av);
- int max_2i = 1;
- for (int i = 0; i < n; i++)
- if (fabs(av_sum - st[i].av) > max_1)
- {
- max_2 = max_1;
- max_2i = max_1i;
- printf("/n%s/n", st[max_2i].surname);
- max_1 = fabs(av_sum - st[i].av);
- max_1i = i;
- printf("/n%s/n", st[max_1i].surname);
- }
- for (int i = max_1i; i < n; i++)
- {
- st[i] = st[i + 1];
- }
- for (int i = max_2i - 1; i < n; i++)
- st[i] = st[i + 1];
- return EXIT_SUCCESS;
- }
- int main()
- {
- int n;
- printf("Input count of students: ");
- scanf("%d", &n);
- if (struct_input(st, n) == EXIT_FAILURE)
- return EXIT_FAILURE;
- del_student(st, n);
- struct_output(st, n);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement