Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Student{
  5.  
  6. int indeks;
  7. int predmet;
  8. int ocjena;
  9.  
  10. };
  11.  
  12. int main() {
  13. FILE *ulaz;
  14. struct Student s[100];
  15. int brojac=0;
  16. float prolaz=0;
  17. int i;
  18. int slusao=0;
  19. int predmt;
  20. float suma=0;
  21. ulaz = fopen("ispiti.txt", "r");
  22. if (ulaz == NULL) {
  23. printf ("Pogreska kod otvaranja datoteke ispiti .txt!\n");
  24. exit(1);
  25. }
  26.  
  27. while(fscanf(ulaz," %d %d %d\n",&s[brojac].indeks,&s[brojac].predmet,&s[brojac].ocjena)==3){
  28. brojac++;}
  29.  
  30. printf("Unesite predmet: ");
  31. scanf("%d",&predmt);
  32.  
  33. for(i=0;i<brojac;i++){
  34. if(s[i].predmet==predmt){
  35. suma+=s[i].ocjena;
  36. slusao++;
  37. if(s[i].ocjena>=6)
  38. prolaz++;
  39. }
  40.  
  41. }
  42. if(slusao==0){
  43. printf("Zalimo, ali ne postoje podaci o predmetu sa brojem %d!",predmt);
  44. return 1;
  45. }
  46. printf("Prosjecna ocjena: %.2f\n",suma/slusao);
  47. printf("Prolaznost: %g%%",(prolaz/slusao)*100);
  48.  
  49. fclose(ulaz);
  50.  
  51. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement