Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define N 5
- struct player
- {
- char name[30];
- int seq;
- int point;
- };
- struct player input(struct player st[],int n);
- struct player output(struct player st[],int n);
- void swap(struct player *xp, struct player *yp);
- void selectionSort(struct player st[], int n);
- void main()
- {
- struct player s[N];
- printf("Enter name and points of 5 players\n");
- input(s,N);
- selectionSort(s, N);
- output(s,N);
- }
- struct player input(struct player st[],int n)
- {
- for(int i=0; i<n; i++)
- {
- st[i].seq=i+1;
- printf("information of player number %d\n",st[i].seq);
- printf("enter name : ");
- scanf("%s",st[i].name);
- printf("enter points : ");
- scanf("%d",&st[i].point);
- }
- }
- void swap(struct player *xp, struct player *yp)
- {
- struct player temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void selectionSort(struct player st[], int n)
- {
- int i, j, min_idx;
- for (i = 0; i < n-1; i++)
- {
- min_idx = i;
- for (j = i+1; j < n; j++)
- if (st[j].point > st[min_idx].point)
- min_idx = j;
- swap(&st[min_idx], &st[i]);
- }
- }
- struct player output(struct player st[],int n)
- {
- printf("\nplayers info in terms of points\n");
- printf("\n\tRANK\t\t\tNAME\t\t\tPOINT\n");
- printf("-----------------------------------------------------------------------\n");
- for(int i=0; i<n; i++)
- {
- printf("\t%d\t\t\t%s\t\t\t%d\n",i+1,st[i].name,st[i].point);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement