Advertisement
Guest User

meanm

a guest
Jan 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. struct lista {
  5. int i;
  6. struct lista *next;
  7. };
  8. int meanm(struct lista *,int,int);
  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("%d",meanm(p,1,6));
  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. int meanm(struct lista *gl,int m,int n){
  41. struct lista *p,*pom,*pom1;
  42. int i,br=0,suma=0;
  43. p=gl;
  44. while(p!=NULL){
  45.     br++;
  46.     p=p->next;
  47. }
  48. if((m>0 && m<br)&&(n>0 && n<br)){
  49.     p=gl;
  50.     i=1;
  51.      while(p!=NULL){
  52.         if(i==m){
  53.                 break;
  54.         }
  55.         p=p->next;
  56.         i++;
  57.      }
  58.      pom=m;
  59.      p=p->next;
  60.      while(p!=NULL){
  61.         if(i==n){
  62.                 break;
  63.         }
  64.         p=p->next;
  65.         i++;
  66.      }
  67.      pom1=n;
  68.      p=gl;
  69.      i=1;
  70.      while(p!=NULL){
  71.      if(i>=pom && i<=pom1){
  72.         suma=suma+p->i;
  73.      }
  74.      p=p->next;
  75.      i++;
  76. }
  77. return suma;
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement