fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. static int count;
  5. typedef struct {
  6. char name[30];
  7. int mark;
  8. }student;
  9.  
  10. void main(){
  11. int temp,temp1;
  12. int temp2;
  13. char temp3[30];
  14. student sv[100];
  15. printf("Input the number of students in class: ");
  16. scanf("%d",&count);
  17. for(temp=0;temp<count;temp++)
  18. {
  19. printf("Input name for student %d: ", temp+1);
  20. while(getchar() == '\n');
  21. gets(sv[temp].name);
  22. printf("Input mark for student %d: ", temp+1);
  23. scanf("%d", &sv[temp].mark);
  24. }
  25. for(temp=0;temp<count;temp++)
  26. {
  27. for(temp1=temp+1;temp1<count;temp1++)
  28. {
  29. if(sv[temp].mark>sv[temp1].mark)
  30. {
  31. temp2=sv[temp].mark;
  32. sv[temp].mark=sv[temp1].mark;
  33. sv[temp1].mark=temp2;
  34. strcpy(temp3,sv[temp].name);
  35. strcpy(sv[temp].name,sv[temp1].name);
  36. strcpy(sv[temp1].name,temp3);
  37. }
  38. }
  39. }
  40. for(temp=0;temp<count;temp++)
  41. {
  42. printf("Student %d:\n",temp+1);
  43. printf("Name: %s --- Mark: %d\n",sv[temp].name,sv[temp].mark);
  44. }
  45. }
  46.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Input the number of students in class: