Advertisement
Guest User

Svi zadaci

a guest
Oct 23rd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. //Prvi zadatak
  2.  
  3. void BrojUsamljenihJedinica(int **a, int m, int n)
  4. {
  5. int i, j, br=0;
  6. for(i=0; i<m, i++)
  7. {
  8. for(j=0; j<n; j++)
  9. {
  10. if(a[i][j]==1)
  11. {
  12. if( ((i-1<0)||(j-1<0)||(a[i-1][j-1]!=1)) &&
  13. ((i-1<0)||(a[i-1][j]!=1)) &&
  14. ((i-1<0)||(j+1>=n)||(a[i-1][j+1]!=1)) &&
  15. ((i+1>=m)||(j-1<0)||(a[i+1][j-1]!=1)) &&
  16. ((i+1>=m)||(a[i+1][j]!=1)) &&
  17. ((i+1>=m)||(j+1>=n)||(a[i+1][j+1]!=1)) &&
  18. ((j-1<0)||(a[i][j-1]!=1)) &&
  19. ((j+1>=n)||(a[i][j+1]!=1)))
  20. br++;
  21. }
  22. }
  23. }
  24. printf("%d", br);
  25. return;
  26. }
  27.  
  28. //Drugi zadatak
  29.  
  30. //a)
  31. void zbroj(float **a, float **b, int n)
  32. {
  33. int i, j;
  34. for(i=0; i<n; i++)
  35. for(j=0; j<n; j++)
  36. a[i][j]+=b[i][j];
  37. return;
  38. }
  39.  
  40. //b)
  41. float suma(float **a, int n)
  42. {
  43. int i, sum=0;
  44. for(i=0; i<n; i++)
  45. {
  46. sum+=a[i][n-i-1];
  47. }
  48. return sum;
  49. }
  50.  
  51. //c)
  52. void zamjena(float **a, int n)
  53. {
  54. float temp=a[0][0];
  55. a[0][0]=a[n-1][n-1];
  56. a[n-1][n-1]=temp;
  57. return;
  58. }
  59.  
  60. //d)
  61. void transponirana(float **a, int n)
  62. {
  63. float **b=a;
  64. int i, j;
  65. for(i=0; i<n; i++)
  66. for(j=0; j<n; j++)
  67. a[i][j]=b[j][i];
  68. return;
  69. }
  70.  
  71. //Treci zadatak
  72.  
  73. typedef struct list{
  74. int x;
  75. struct list * next;
  76. } list_t;
  77.  
  78. list_t* NapraviListu()
  79. {
  80. int i, a[]=(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);
  81.  
  82. list_t *head, *current, *temp;
  83. head=(list_t*)malloc(sizeof(list_t));
  84. current=head;
  85. head->next=NULL;
  86.  
  87. for(i=0; i<9; i++)
  88. {
  89. temp=(list_t*)malloc(sizeof(list_t));
  90. current->next=temp;
  91. current->x=a[i];
  92. current=temp;
  93. free(temp);
  94. }
  95. current->next=NULL;
  96. current->x=a[9];
  97.  
  98. return head;
  99. }
  100.  
  101. void Dodaj()
  102. {
  103. int i, j=0, a[]=(8, 22, 458);
  104. list_t *current=NapraviListu(), *temp;
  105.  
  106. for(i=0; i<10; i++)
  107. {
  108. if(a[j]>current->x && a[j]<current->next->x)
  109. {
  110. temp=(list_t*)malloc(sizeof(list_t));
  111. temp->next=current->next;
  112. temp->x=a[j];
  113. current->next=temp;
  114. j++;
  115. }
  116. current=current->next;
  117. if(j==3)
  118. return;
  119. }
  120. }
  121.  
  122. //Cetvrti zadatak
  123.  
  124. typedef struct list{
  125. int x;
  126. struct list * next;
  127. } list_t;
  128.  
  129. void Ubaci(list_t *head)
  130. {
  131. list_t *prethodni1, *prethodni2, *temp;
  132. prethodni1=head->next;
  133. prethodni2=head;
  134.  
  135. while(1)
  136. {
  137. temp=(list_t*)malloc(sizeof(list_t));
  138. temp->x=prethodni1->x+prethodni2->x;
  139. temp->next=prethodni1->next;
  140. prethodni1->next=temp;
  141.  
  142. if(temp->next==NULL || temp->next->next==NULL)
  143. return;
  144.  
  145. prethodni2=temp->next;
  146. prethodni1=prethodni2->next;
  147. }
  148. }
  149.  
  150. //Peti zadatak
  151.  
  152. typedef struct list{
  153. float x;
  154. struct list *next;
  155. } list_t;
  156.  
  157. typedef struct list2{
  158. list_t *x;
  159. struct list2 *next;
  160. } list2_t;
  161.  
  162. list_t* NapraviListu(float *a, int n)
  163. {
  164. int i;
  165.  
  166. list_t *head, *current, *temp;
  167. head=(list_t*)malloc(sizeof(list_t));
  168. current=head;
  169. head->next=NULL;
  170.  
  171. for(i=0; i<n; i++)
  172. {
  173. temp=(list_t*)malloc(sizeof(list_t));
  174. current->next=temp;
  175. current->x=a[i];
  176. current=temp;
  177. free(temp);
  178. }
  179. current->next=NULL;
  180.  
  181. return head;
  182. }
  183.  
  184. void obrisi(float **a, int m, int n, float x)
  185. {
  186. int i;
  187. list2_t *prvi, *current, *temp;
  188. list_t *trenutni, *t;
  189.  
  190. prvi=(list2_t*)malloc(sizeof(list2_t));
  191. current=head;
  192. prvi->next=NULL;
  193.  
  194. for(i=0; i<m; i++)
  195. {
  196. temp=(list2_t*)malloc(sizeof(list2_t));
  197. current->next=temp;
  198. current->x=NapraviListu(a[i], n);
  199. current=temp;
  200. free(temp);
  201. }
  202. current->next=NULL;
  203.  
  204. current=prvi;
  205.  
  206. do
  207. {
  208. trenutni=current->x;
  209. if(current->x->x==x)
  210. current->x=trenutni->next;
  211. do
  212. {
  213. if (trenutni->next->x==x)
  214. {
  215. t=trenutni->next->next;
  216. free(trenutni->next);
  217. trenutni->next=t;
  218. }
  219. else
  220. {
  221. trenutni=trenutni->next;
  222. }
  223. } while(trenutni->next!=NULL);
  224.  
  225. current=current->next;
  226. } while(current->next!=NULL);
  227.  
  228. return;
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement