Advertisement
damch

zadaca studenti strukturi

Mar 9th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. struct student{
  6. char ime[20];
  7. char prezime[40];
  8. int indeks;
  9. int zad1,zad2,zad3,zad4;
  10. };
  11.  
  12. typedef struct student student;
  13.  
  14. void polni(student *s){
  15. scanf("%s",&s->ime);
  16. scanf("%s",&s->prezime);
  17. scanf("%d",&s->indeks);
  18. scanf("%d %d %d %d",&s->zad1,&s->zad2,&s->zad3,&s->zad4);
  19. }
  20. int vkupnobod(student s){
  21. return s.zad1+s.zad2+s.zad3+s.zad4;
  22. }
  23. void sredi(char *s){
  24. *s = toupper(*s);
  25. while (*(++s) != '\0')
  26. *s = tolower(*s);
  27. }
  28. void sort(student a[], int n) {
  29. int i, j;
  30. student s;
  31. for (i = 0; i < n; i++)
  32. for (j = 0; j < n - i - 1; j++)
  33. if (vkupnobod(a[j]) < vkupnobod(a[j+1])) {
  34. s = a[j];
  35. a[j] = a[j + 1];
  36. a[j + 1] = s;
  37. }
  38. }
  39. int main()
  40. {
  41. int i;
  42. int n;
  43. student a[50];
  44. scanf("%d",&n);
  45. for(i=0;i<n;i++)
  46. {
  47. polni(&a[i]);
  48. sredi(a[i].prezime);
  49. }
  50. sort(a,n);
  51.  
  52. for (i = 0; i < n; i++) {
  53. printf("%d. %s %s %d %d\n", i+1, a[i].ime, a[i].prezime, a[i].indeks, vkupnobod(a[i]));
  54. }
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement