Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE 100
- int main(int argc, char *argv[]) {
- struct student
- {
- char name[SIZE];
- char group[SIZE];
- double ses[4];
- };
- _Bool isSorted = 1, flag4 = 1;
- int i, x, j, choice = 1, flag = 0, amountOfStudents = 3;
- double buf = 0.0, bufAv, average[SIZE], group[SIZE];
- struct student stud[4];
- struct student studBuf;
- while(choice)
- {
- printf("1- Enter list of studentsn2 - Output list of studentsnEnter your
- choice: ");
- scanf("%d", &choice);
- switch(choice)
- {
- case 1:
- for(i = 0; i < amountOfStudents; i++)
- {
- printf("Enter name:");
- scanf("%s", &stud[i].name);
- printf("Enter group:");
- scanf("%s",&stud[i].group);
- printf("Enter marks of students:");
- for(j = 0; j < 4; j++)
- {
- scanf("%lf", &stud[i].ses[j]);
- buf += stud[i].ses[j];
- }
- average[i] = buf / 4;
- printf("average:%gn", average[i]);
- buf = 0;
- }
- isSorted = 1;
- while(isSorted)
- {
- isSorted = 0;
- for(i = 0; i < amountOfStudents-1; i++)
- {
- if(group[i]<group[i+1])
- {
- studBuf = stud[i+1];
- stud[i+1] = stud[i];
- stud[i] = studBuf;
- }
- if(group[i]<group[i+1])
- {
- isSorted = 1;
- buf = group[i+1];
- group[i+1] = group[i];
- group[i] = buf;
- }
- }
- }
- break;
- case 2:
- for(i = 0; i < amountOfStudents; i++)
- {
- printf("%s [%s] ", stud[i].name, stud[i].group);
- printf("Average: %gn ", average[i]);
- printf("Marks: ");
- for(j = 0; j < 4; j++)
- {
- if(average[i] >= 4 )
- flag++;
- else
- {
- flag = 0;
- flag4 = 0;
- }
- printf("%g ", stud[i].ses[j]);
- }
- printf("n");
- if(flag >= 2)
- printf("Student %s [%s] has 4 and more n", stud[i].name,
- stud[i].group);
- flag = 0;
- flag4 = 1;
- }
- break;
- default:
- printf("Your enter is wrong!");
- break;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment