Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct lista {
- int i;
- struct lista *next;
- };
- void sredina(struct lista *);
- void print_lista(struct lista *);
- void main(){
- struct lista *p,*q,*t;
- int n;
- p=(struct lista *)malloc(sizeof(struct lista));
- p->next=NULL;
- scanf("%d",&n);
- p->i=n;
- t=p;
- while(n<30){
- q=(struct lista *)malloc(sizeof(struct lista));
- scanf("%d",&n);
- q->next=NULL;
- q->i=n;
- t->next=q;
- t=q;
- }
- print_lista(p);
- printf("%f",sredina(p));
- }
- void print_lista(struct lista *p){
- struct lista *q=p;
- while(q!=NULL){
- printf("%d ",q->i);
- q=q->next;
- }
- }
- void sredina(struct lista *gl){
- struct lista *p;
- int i,br=0,suma=0,pom;
- float ar;
- p=gl;
- while(p->next!=NULL){
- p=p->next;
- }
- pom=p->i;
- p=gl;
- i=1;
- while(p!=NULL){
- if(pom>p->i){
- suma=suma+p->i;
- br++;
- }
- }
- ar=(float)suma/(float)br;
- return ar;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement