Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Student
- {
- int ID;
- char name[50];
- int points;
- }ar[200];
- int main(){ int i,n,swap,j;
- printf("Pass the number of students to the program: ");
- scanf("%d",&n);
- for(i=1;i<=n;++i)
- {
- printf("Input ID of student %d: ", i);
- scanf("%d",&ar[i].ID );
- printf("Input name of student %d: ", i);
- scanf("%s", &ar[i].name);
- printf("Input points of student %d: ", i);
- scanf("%d", &ar[i].points); }
- printf("BEFORE SORT");
- for(i=1;i<n+1;i++)
- {
- printf("\nID %d is %d ", i, ar[i].ID);
- printf("\tName %d is %s ", i,ar[i].name);
- printf("\tPoints %d are %d ", i, ar[i].points);
- }
- for(i=0;i<n-1;i++)
- {
- for(j=0;j<n-i;j++)
- {struct Student swap;
- if(ar[j].points>ar[j+1].points){
- swap=ar[j];
- ar[j]=ar[j+1];
- ar[j+1]=swap;
- }}
- }
- printf("\nSORTED IN ASCENDING ORDER");
- for(i=1;i<n+1;i++)
- {
- printf("\nID %d is %d ", i, ar[i].ID);
- printf("\tName %d is %s ", i,ar[i].name);
- printf("\tPoints %d are %d ", i, ar[i].points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement