SHARE
TWEET

Untitled

a guest May 24th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAX 128
  6.  
  7. struct student
  8. {
  9.     char surname[MAX];
  10.     int exams[3];
  11.     double av;
  12. } st[MAX];
  13.  
  14. typedef struct student struct_t[MAX];
  15.  
  16. int struct_input(struct_t st, int n)
  17. {
  18.     for (int i = 0; i < n; i++)
  19.     {
  20.         printf("Input Surname: ");
  21.         if (scanf("%s", st[i].surname) != 1)
  22.             return EXIT_FAILURE;
  23.  
  24.         printf("Input marks: ");
  25.         if (scanf("%d %d %d", &st[i].exams[0], &st[i].exams[1], &st[i].exams[2]) != 3)
  26.             return EXIT_FAILURE;
  27.     }
  28.     return EXIT_SUCCESS;
  29. }
  30.  
  31. int struct_output(struct_t st, int n)
  32. {
  33.     for (int i = 0; i < n - 2; i++)
  34.     {
  35.         printf("\nSurname is %s", st[i].surname);
  36.         printf("\nMarks are: %d %d %d", st[i].exams[0], st[i].exams[1], st[i].exams[2]);
  37.         st[i].av = (st[i].exams[0] + st[i].exams[1] + st[i].exams[2]) / 3.0;
  38.         printf("\nAverage score is: %lf", st[i].av);
  39.     }
  40.     return EXIT_SUCCESS;
  41. }
  42.  
  43. int del_student(struct_t st, int n)
  44. {
  45.     double sum = 0.0;
  46.     double av_sum;
  47.  
  48.     for (int i = 0; i < n; i++)
  49.         sum += st[i].av;
  50.  
  51.     av_sum = sum / n;
  52.  
  53.     float max_1 = fabs(av_sum - st[0].av);
  54.     int max_1i = 0;
  55.     float max_2 = fabs(av_sum - st[1].av);
  56.     int max_2i = 1;
  57.  
  58.     for (int i = 0; i < n; i++)
  59.         if (fabs(av_sum - st[i].av) > max_1)
  60.         {
  61.             max_2 = max_1;
  62.             max_2i = max_1i;
  63.             printf("/n%s/n", st[max_2i].surname);
  64.             max_1 = fabs(av_sum - st[i].av);
  65.             max_1i = i;
  66.             printf("/n%s/n", st[max_1i].surname);
  67.         }
  68.  
  69.     for (int i = max_1i; i < n; i++)
  70.     {
  71.         st[i] = st[i + 1];
  72.     }
  73.     for (int i = max_2i - 1; i < n; i++)
  74.         st[i] = st[i + 1];
  75.  
  76.     return EXIT_SUCCESS;
  77. }
  78.  
  79. int main()
  80. {
  81.     int n;
  82.  
  83.     printf("Input count of students: ");
  84.     scanf("%d", &n);
  85.  
  86.     if (struct_input(st, n) == EXIT_FAILURE)
  87.         return EXIT_FAILURE;
  88.     del_student(st, n);
  89.     struct_output(st, n);
  90.  
  91.     return EXIT_SUCCESS;
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top