Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define SIZE 30
- typedef struct student{
- int id;
- int help;
- char name[SIZE];
- char *task[SIZE];
- }student;
- void swap(student *xp, student *yp)
- {
- student temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void bubbleSort(student arr[], int n)
- {
- int i, j;
- for (i = 0; i < n - 1; i++)
- // Last i elements are already in place
- for (j = 0; j < n - i - 1; j++)
- if (arr[j].help <= arr[j + 1].help)
- swap(&arr[j], &arr[j + 1]);
- }
- void swap2(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void bubbleSort2(int arr[], int n)
- {
- int i, j;
- for (i = 0; i < n - 1; i++)
- // Last i elements are already in place
- for (j = 0; j < n - i - 1; j++)
- if (arr[j] <= arr[j + 1])
- swap2(&arr[j], &arr[j + 1]);
- }
- int main(void)
- {
- int i;
- int noSessions;
- int noStudents;
- printf("Enter number of consultation sesssions: ");
- scanf("%d", &noSessions);
- //create an array of sessions.
- int sessionCount[noSessions];
- printf("Enter number of students: ");
- scanf("%d", &noStudents);
- student arr[SIZE];
- for (i = 0; i < noStudents; i++) {
- int j = i + 1;
- printf("Enter enter student %d ID, name and consultation session.", j);
- scanf("%d" "%s" "%d", &arr[i].id, arr[i].name, &arr[i].help);
- //increment the number of people in that particular session.
- sessionCount[arr[i].help]++;
- }
- printf("Student ID == Full Name == Consultation Session");
- bubbleSort(arr, noStudents);
- for (i = 0; i < noStudents; i++) {
- printf("\n");
- printf(" %d <> %s <> %d", arr[i].id, arr[i].name, arr[i].help);
- printf("\n");
- }
- //print the number of people in each session
- for (i = 0; i < noSessions; i++) {
- printf("\n");
- printf("%d, %d", i, sessionCount[i]);
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement