Skip to content

Instantly share code, notes, and snippets.

@darkodemic
Forked from anonymous/gist:ed32a0a5b165af326429
Last active August 29, 2015 14:22
Show Gist options
  • Save darkodemic/e9c87725b2c44baeeb29 to your computer and use it in GitHub Desktop.
Save darkodemic/e9c87725b2c44baeeb29 to your computer and use it in GitHub Desktop.
Pisanje i citanje u struct
#include <stdio.h>
#include <stdlib.h>
struct imenik{
char ime[30];
int brtel;
float prosek[10];
};
float average(int ocene[30], int f){
int a;
float y=0,x=0;
for(a=0;a<f;a++){
x+= ocene[a];
}
y = x/f;
return y;
}
main(){
int i,n,f=0, ocene[30];
float y;
struct imenik x;
printf("Unesite ime:");
scanf("%s",&x.ime);
printf("Vase ime je:%s\n",x.ime);
printf("Unesite broj telefona:\n");
scanf("%d",&x.brtel);
printf("Vas broj telefona je:%d\n",x.brtel);
printf("Unesite broj predmeta:");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("Ocena:");
scanf("%d",&ocene[i]);
f++;
}
y = average(ocene,f);
printf("Vas prosek je %lf",y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment