Advertisement
Guest User

nadovezi

a guest
Jan 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. struct lista {
  5. int i;
  6. struct lista *next;
  7. };
  8. void Nadovezi(struct lista *,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.  
  29.     Nadovezi(p,3);
  30.     printf("nova lista je");
  31.     print_lista(p);
  32.  
  33. }
  34.  
  35. void print_lista(struct lista *p){
  36. struct lista *q=p;
  37. while(q!=NULL){
  38.     printf("%d ",q->i);
  39.     q=q->next;
  40.     }
  41.  
  42. }
  43. void Nadovezi(struct lista *gl,int n){
  44. struct lista *p,*Nrep;
  45. int i,a;
  46. p=gl;
  47. i=1;
  48. while(p!=NULL){
  49.     if((p->i)%n==0){
  50.            Nrep=(struct lista *)malloc(sizeof(struct lista));
  51.            Nrep->i=p->i+p->next->i;
  52.            p->next=Nrep;
  53.            Nrep->next=p->next->next;
  54.            i++;
  55.            p=p->next;
  56.     }
  57.     else{
  58.         i++;
  59.         p=p->next;
  60.     }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement