Advertisement
Guest User

lista sredina repa

a guest
Jan 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. struct lista {
  5. int i;
  6. struct lista *next;
  7. };
  8. void sredina(struct lista *);
  9. void print_lista(struct lista *);
  10.  
  11. void main(){
  12. struct lista *p,*q,*t;
  13. int n;
  14. p=(struct lista *)malloc(sizeof(struct lista));
  15. p->next=NULL;
  16. scanf("%d",&n);
  17. p->i=n;
  18. t=p;
  19. while(n<30){
  20.     q=(struct lista *)malloc(sizeof(struct lista));
  21.     scanf("%d",&n);
  22.     q->next=NULL;
  23.     q->i=n;
  24.     t->next=q;
  25.     t=q;
  26.     }
  27.     print_lista(p);
  28.     printf("%f",sredina(p));
  29.  
  30. }
  31.  
  32. void print_lista(struct lista *p){
  33. struct lista *q=p;
  34. while(q!=NULL){
  35.     printf("%d ",q->i);
  36.     q=q->next;
  37.     }
  38.  
  39. }
  40. void sredina(struct lista *gl){
  41. struct lista *p;
  42. int i,br=0,suma=0,pom;
  43. float ar;
  44. p=gl;
  45. while(p->next!=NULL){
  46.     p=p->next;
  47. }
  48. pom=p->i;
  49. p=gl;
  50. i=1;
  51. while(p!=NULL){
  52.     if(pom>p->i){
  53.         suma=suma+p->i;
  54.            br++;
  55.     }
  56. }
  57. ar=(float)suma/(float)br;
  58. return ar;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement