Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Prvi zadatak
- void BrojUsamljenihJedinica(int **a, int m, int n)
- {
- int i, j, br=0;
- for(i=0; i<m, i++)
- {
- for(j=0; j<n; j++)
- {
- if(a[i][j]==1)
- {
- if( ((i-1<0)||(j-1<0)||(a[i-1][j-1]!=1)) &&
- ((i-1<0)||(a[i-1][j]!=1)) &&
- ((i-1<0)||(j+1>=n)||(a[i-1][j+1]!=1)) &&
- ((i+1>=m)||(j-1<0)||(a[i+1][j-1]!=1)) &&
- ((i+1>=m)||(a[i+1][j]!=1)) &&
- ((i+1>=m)||(j+1>=n)||(a[i+1][j+1]!=1)) &&
- ((j-1<0)||(a[i][j-1]!=1)) &&
- ((j+1>=n)||(a[i][j+1]!=1)))
- br++;
- }
- }
- }
- printf("%d", br);
- return;
- }
- //Drugi zadatak
- //a)
- void zbroj(float **a, float **b, int n)
- {
- int i, j;
- for(i=0; i<n; i++)
- for(j=0; j<n; j++)
- a[i][j]+=b[i][j];
- return;
- }
- //b)
- float suma(float **a, int n)
- {
- int i, sum=0;
- for(i=0; i<n; i++)
- {
- sum+=a[i][n-i-1];
- }
- return sum;
- }
- //c)
- void zamjena(float **a, int n)
- {
- float temp=a[0][0];
- a[0][0]=a[n-1][n-1];
- a[n-1][n-1]=temp;
- return;
- }
- //d)
- void transponirana(float **a, int n)
- {
- float **b=a;
- int i, j;
- for(i=0; i<n; i++)
- for(j=0; j<n; j++)
- a[i][j]=b[j][i];
- return;
- }
- //Treci zadatak
- typedef struct list{
- int x;
- struct list * next;
- } list_t;
- list_t* NapraviListu()
- {
- int i, a[]=(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);
- list_t *head, *current, *temp;
- head=(list_t*)malloc(sizeof(list_t));
- current=head;
- head->next=NULL;
- for(i=0; i<9; i++)
- {
- temp=(list_t*)malloc(sizeof(list_t));
- current->next=temp;
- current->x=a[i];
- current=temp;
- free(temp);
- }
- current->next=NULL;
- current->x=a[9];
- return head;
- }
- void Dodaj()
- {
- int i, j=0, a[]=(8, 22, 458);
- list_t *current=NapraviListu(), *temp;
- for(i=0; i<10; i++)
- {
- if(a[j]>current->x && a[j]<current->next->x)
- {
- temp=(list_t*)malloc(sizeof(list_t));
- temp->next=current->next;
- temp->x=a[j];
- current->next=temp;
- j++;
- }
- current=current->next;
- if(j==3)
- return;
- }
- }
- //Cetvrti zadatak
- typedef struct list{
- int x;
- struct list * next;
- } list_t;
- void Ubaci(list_t *head)
- {
- list_t *prethodni1, *prethodni2, *temp;
- prethodni1=head->next;
- prethodni2=head;
- while(1)
- {
- temp=(list_t*)malloc(sizeof(list_t));
- temp->x=prethodni1->x+prethodni2->x;
- temp->next=prethodni1->next;
- prethodni1->next=temp;
- if(temp->next==NULL || temp->next->next==NULL)
- return;
- prethodni2=temp->next;
- prethodni1=prethodni2->next;
- }
- }
- //Peti zadatak
- typedef struct list{
- float x;
- struct list *next;
- } list_t;
- typedef struct list2{
- list_t *x;
- struct list2 *next;
- } list2_t;
- list_t* NapraviListu(float *a, int n)
- {
- int i;
- list_t *head, *current, *temp;
- head=(list_t*)malloc(sizeof(list_t));
- current=head;
- head->next=NULL;
- for(i=0; i<n; i++)
- {
- temp=(list_t*)malloc(sizeof(list_t));
- current->next=temp;
- current->x=a[i];
- current=temp;
- free(temp);
- }
- current->next=NULL;
- return head;
- }
- void obrisi(float **a, int m, int n, float x)
- {
- int i;
- list2_t *prvi, *current, *temp;
- list_t *trenutni, *t;
- prvi=(list2_t*)malloc(sizeof(list2_t));
- current=head;
- prvi->next=NULL;
- for(i=0; i<m; i++)
- {
- temp=(list2_t*)malloc(sizeof(list2_t));
- current->next=temp;
- current->x=NapraviListu(a[i], n);
- current=temp;
- free(temp);
- }
- current->next=NULL;
- current=prvi;
- do
- {
- trenutni=current->x;
- if(current->x->x==x)
- current->x=trenutni->next;
- do
- {
- if (trenutni->next->x==x)
- {
- t=trenutni->next->next;
- free(trenutni->next);
- trenutni->next=t;
- }
- else
- {
- trenutni=trenutni->next;
- }
- } while(trenutni->next!=NULL);
- current=current->next;
- } while(current->next!=NULL);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement