Guest User

Untitled

a guest
Dec 10th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define SIZE 100
  4.  
  5. int main(int argc, char *argv[]) {
  6. struct student
  7. {
  8. char name[SIZE];
  9. char group[SIZE];
  10. double ses[4];
  11. };
  12. _Bool isSorted = 1, flag4 = 1;
  13. int i, x, j, choice = 1, flag = 0, amountOfStudents = 3;
  14. double buf = 0.0, bufAv, average[SIZE], group[SIZE];
  15. struct student stud[4];
  16. struct student studBuf;
  17. while(choice)
  18. {
  19. printf("1- Enter list of studentsn2 - Output list of studentsnEnter your
  20. choice: ");
  21. scanf("%d", &choice);
  22.  
  23. switch(choice)
  24. {
  25. case 1:
  26. for(i = 0; i < amountOfStudents; i++)
  27. {
  28. printf("Enter name:");
  29. scanf("%s", &stud[i].name);
  30. printf("Enter group:");
  31. scanf("%s",&stud[i].group);
  32. printf("Enter marks of students:");
  33. for(j = 0; j < 4; j++)
  34. {
  35. scanf("%lf", &stud[i].ses[j]);
  36. buf += stud[i].ses[j];
  37. }
  38. average[i] = buf / 4;
  39. printf("average:%gn", average[i]);
  40. buf = 0;
  41. }
  42. isSorted = 1;
  43. while(isSorted)
  44. {
  45. isSorted = 0;
  46. for(i = 0; i < amountOfStudents-1; i++)
  47. {
  48. if(group[i]<group[i+1])
  49. {
  50. studBuf = stud[i+1];
  51. stud[i+1] = stud[i];
  52. stud[i] = studBuf;
  53. }
  54. if(group[i]<group[i+1])
  55. {
  56. isSorted = 1;
  57. buf = group[i+1];
  58. group[i+1] = group[i];
  59. group[i] = buf;
  60. }
  61. }
  62. }
  63. break;
  64.  
  65. case 2:
  66. for(i = 0; i < amountOfStudents; i++)
  67. {
  68. printf("%s [%s] ", stud[i].name, stud[i].group);
  69. printf("Average: %gn ", average[i]);
  70. printf("Marks: ");
  71. for(j = 0; j < 4; j++)
  72. {
  73. if(average[i] >= 4 )
  74. flag++;
  75. else
  76. {
  77. flag = 0;
  78. flag4 = 0;
  79. }
  80. printf("%g ", stud[i].ses[j]);
  81. }
  82. printf("n");
  83. if(flag >= 2)
  84. printf("Student %s [%s] has 4 and more n", stud[i].name,
  85. stud[i].group);
  86. flag = 0;
  87. flag4 = 1;
  88. }
  89. break;
  90.  
  91. default:
  92. printf("Your enter is wrong!");
  93. break;
  94. }
  95. }
  96. return 0;
  97. }
Add Comment
Please, Sign In to add comment