Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define DIM 100
  4. void crearray(int*,int);
  5. void visualizza(int*,int);
  6. struct lista
  7. {
  8. int num;
  9. int ugdiv;
  10. struct lista *next;
  11. };
  12. struct lista *crealista(struct lista*,int,int*,int*);
  13. void visualizzalista(struct lista *);
  14. int main()
  15. {
  16. int N,v[DIM],v1[DIM];
  17. struct lista *s=NULL;
  18. printf("inserire dimensione array: ");
  19. scanf("%d",&N);
  20. printf ("\ninserimento primo array; \n");
  21. crearray(v,N);
  22. printf("primo array: \n");
  23. visualizza(v,N);
  24. printf ("\ninserimento secondo array; \n");
  25. crearray(v1,N);
  26. printf("secondo array: \n");
  27. visualizza(v1,N);
  28. crealista(s,N,v,v1);
  29. visualizzalista(s);
  30. }
  31. void crearray(int*a,int b)
  32. {
  33. int i;
  34. for (i=0;i<b;i++)
  35. {
  36. printf("inserire %d' valore ",i+1);
  37. scanf("%d",a+i);
  38. }
  39. }
  40. void visualizza(int*a,int b)
  41. {
  42. int i;
  43. for (i=0;i<b;i++)
  44. printf("%d ",*(a+i));
  45. }
  46. struct lista *crealista(struct lista *p, int a, int *b, int *c)
  47. {
  48. int i=0;
  49. struct lista *paux;
  50. p=(struct lista*)malloc(sizeof(struct lista));
  51. paux=p;
  52. while (i<a)
  53. {
  54. paux->next=(struct lista*)malloc(sizeof(struct lista));
  55. paux=paux->next;
  56. paux->next=NULL;
  57. if(b[i]==c[i])
  58. {
  59. paux->num=i+1;
  60. paux->ugdiv=1;
  61. }
  62. else
  63. {
  64. paux->num=i+1;
  65. paux->ugdiv=0;
  66. }
  67. i++;
  68. }
  69. return p;
  70. }
  71. void visualizzalista(struct lista *p)
  72. {
  73. while (p!=NULL)
  74. {
  75. printf (" (%d,%d)-> ", p->num, p->ugdiv);
  76. p=p->next;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement